Day 3/#30daysofK8s

Commands & args — to pass commands and args to a container inside pod the way it is done with docker, we add command and args key to the spec.containers.<container_list>.

entrypoint -> command
cmd -> args

DockerfileFROM ubuntu
ENTRYPOINT ["sleep"]
CMD ["5"]

pod-def.yaml
apiVersion: v1
kind: Pod
metadata:
name: sleeper-pod-1
spec:
containers:
- name: ubuntu-sleep
image: ubuntu-sleep
command: ["sleep"]
args: ["5"]
  • everything in command has to be a string, it expects a []string array.

k run <pod_name> --image=<image_name> --dry-run=client -o yaml > p.yaml

Makes creating a pod-def file easier ^.

Environment Variables — Can be set in docker via docker run <container_name> -e VAR1=VAL1 --image=<image_name>.

In pod, add a env key to spec.containers list.

spec:
containers:
- name: smh
image: sm_img
env:
- name: APP_COLOR
value: pink

Other ways to set env var is via configmaps.