Shahbaz
Shahbaz

Reputation: 101

How to give annotations by using run command in kubernetes to a pod

I attempted but there is an error..i also see See 'kubectl run --help' for usage. but i can't fix it..

kubectl run pod pod4 --image=aamirpinger/helloworld:latest --port=80 --annotaions=createdBy="Muhammad Shahbaz" --restart=Never

Error: unknown flag: --annotaions

Upvotes: 4

Views: 5413

Answers (3)

Once Upon a Dev
Once Upon a Dev

Reputation: 1108

kubectl run supports specifying annotations via the --annotations flag that can be specified multiple times to apply multiple annotations.

For example:

$ kubectl run --image myimage --annotations="foo=bar" --annotations="another=one" mypod

results in the following:

$ kubectl get pod mypod -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    foo: bar
    another: one
[...]

Upvotes: 8

sachin
sachin

Reputation: 1350

As David Maze mentioned ,there is no --annotations flag for kubectl run command.It is better to write deployment yaml file compared to running using kubectl run command.

However you can add annotations to kubernetes resources using Kubectl annotate command.All Kubernetes objects support the ability to store additional data with the object as annotations.

Hope this helps.

Upvotes: 0

David Maze
David Maze

Reputation: 158647

kubectl run doesn't have an option to set annotations.

Unless you're running a one-off debugging pod, it's usually better practice to write out the full (Deployment) YAML file, commit to source control, and install it using kubectl apply -f. That will let you specify any Kubernetes object property you need to.

Upvotes: 0

Related Questions