Menu

Dipesh Majumdar

Blog and Paintings

Easiest way to write manifests

  • Pod

kubectl -n some_ns run pod_name --restart=Never --image=nginx:1.7.9 --dry-run -o yaml > pod.yaml

Now suppose you want to spin up a pod with some resource constraint this is how you do it - 

kubectl -n mns run nginx20 --restart=Never --image=nginx --requests='cpu=100m,memory=256Mi' --limits='cpu=500m,memory=512Mi' --dry-run -o yaml

What about spinning up 3 pods with nginx1, nginx2 and nginx3

[dipesh.majumdar@demo ~]$ for i in {1..3}; do k run nginx$i --restart=Never --image=nginx --labels=app=v1 ; done;
pod/nginx1 created
pod/nginx2 created
pod/nginx3 created

  • Job:

kubectl run hello --schedule="*/1 * * * *" --restart=OnFailure --image=busybox -- /bin/sh -c "date; echo Hello from the Kubernetes cluster"

Note:

100m means 100 divided by 1000 which is 0.1 core CPU

Also note:
--restart=Always: The restart policy for this Pod. Legal values [Always, OnFailure, Never].

If set to Always a deployment is created, if set to OnFailure a job is created, if set to Never, a regular pod is created. For the latter two --replicas must be 1. Default Always

 

Go Back

Comment