I would like to run specific command after initialization of deployment is successful.
This is my yaml file:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: auth spec: replicas: 1 template: metadata: labels: app: auth spec: containers: - name: auth image: {{my-service-image}} env: - name: NODE_ENV value: "docker-dev" resources: requests: cpu: 100m memory: 100Mi ports: - containerPort: 3000
However, I would like to run command for db migration after (not before) deployment is successfully initialized and pods are running.
I can do it manually for every pod (with kubectl exec), but this is not very scalable.
Define a command and arguments when you create a PodTo define a command, include the command field in the configuration file. To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created.
If you supply a command but no args for a Container, only the supplied command is used. The default EntryPoint and the default Cmd defined in the Docker image are ignored. If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
I resolved it using lifecycles:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: auth spec: replicas: 1 template: metadata: labels: app: auth spec: containers: - name: auth image: {{my-service-image}} env: - name: NODE_ENV value: "docker-dev" resources: requests: cpu: 100m memory: 100Mi ports: - containerPort: 3000 lifecycle: postStart: exec: command: ["/bin/sh", "-c", {{cmd}}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With