Justin Thomas
Justin Thomas

Reputation: 5848

How to deploy new app versions in kubernetes

In this stackoverflow question: kubernetes Deployment. how to change container environment variables for rolling updates?

The asker mentions mentions he edited the deployment to change the version to v2. What's the workflow for automated deployments of a new version assuming the container v2 already exists? How do you then deploy it without manually editing the deployment config or checking in a new version of the yaml?

If you change the underlying container (like v1 -> another version also named v1) will Kubernetes deploy the new or the old?

Upvotes: 1

Views: 1914

Answers (2)

gmolaire
gmolaire

Reputation: 1121

If you don't want to:

  • Checking in the new YAML version
  • Manually updating the config

You can update the deployment either through:

  • A REST call to the deployment in question by patching/putting your new image as a resource modification. i.e. PUT /apis/extensions/v1beta1/namespaces/{namespace}/deployments -d {... deployment with v2...}
  • Set the image kubectl set image deployment/<DEPLOYMENT_NAME> <CONTAINER_NAME>:< IMAGE_NAME>:v2

Upvotes: 2

fishi0x01
fishi0x01

Reputation: 3759

Assuming v1 is already running and you try to deploy v1 again with the same environment variable values etc., then k8s will not see any difference between your current and updated deployment resource. Without diff, the k8s scheduler assumes that the desired state is already reached and won't schedule any new pods, even when imagePullPolicy: Always is set. The reason is that imagePullPolicy only has an effect on newly created pods. So if a new pod is being scheduled, then k8s will always pull the image again. Still, without any diff in your deployment, no new pod will be scheduled in the first place ..

For my deployments I always set a dummy environment variable, like a deploy timestamp DEPLOY_TS, e.g.:

  containers:
  - name: my-app
    image: my-app:{{ .Values.app.version }}  ## value dynamically set by my deployment pipeline
    env:
    - name: DEPLOY_TS
      value: "{{ .Values.deploy_ts }}"  ## value dynamically set by my deployment pipeline

The value of DEPLOY_TS is always set to the current timestamp - so it is always a different value. That way k8s will see a diff on every deploy and schedule a new pod - even if the same version is being re-deployed.

(I am currently running k8s 1.7)

Upvotes: 2

Related Questions