- In Kubernetes Pod YAML files, the “command” field tells the container what to do when the pod starts, and the “args” field gives it any parameter or augments needed.
- This sample java project, takes 2 number as an argument and shows the output.
- In case of a docker image, the way to pass command and arguments is like this
FROM openjdk:17.0.1-jdk-slim COPY target/classes/ /tmp WORKDIR /tmp ENTRYPOINT ["java", org.raj.nola.AddTwoNumbers"] CMD ["5","15"]
ENTRYPOINTis the command which container executes and CMD is the parameter which is passed to the program.
- To do the same in a kubernetes pod, the deployment file will look like below
apiVersion: apps/v1 kind: Deployment metadata: name: cmd-args-example spec: selector: matchLabels: app: cmd-args-example template: metadata: labels: app: cmd-args-example spec: containers: - name: add2numbers image: raje/add2numbers command: [ "java", "org.raj.nola.AddTwoNumbers" ] args: [ "10", "20" ]
- Equivalent of ENTRYPOINT in docker is command in kubernetes and CMD is args.
Thank You !!