Kubernetes rolling update in case of secret update

5/31/2016

I have a Replication Controller with one replica using a secret. How can I update or recreate its (lone) pod—without downtime—with latest secret value when the secret value is changed?

My current workaround is increasing number of replicas in the Replication Controller, deleting the old pods, and changing the replica count back to its original value.

Is there a command or flag to induce a rolling update retaining the same container image and tag? When I try to do so, it rejects my attempt with the following message:

error: Specified --image must be distinct from existing container image
-- Sunil Kumar
google-kubernetes-engine
kubernetes

2 Answers

6/3/2016

If I understand correctly, Deployment should be what you want.

Deployment supports rolling update for almost all fields in the pod template.

See http://kubernetes.io/docs/user-guide/deployments/

-- Lantao Liu
Source: StackOverflow

6/9/2016

A couple of issues #9043 and #13488 describe the problem reasonably well, and I suspect a rolling update approach will eventuate shortly (like most things in Kubernetes), though unlikely for 1.3.0. The same issue applies with updating ConfigMaps.

Kubernetes will do a rolling update whenever anything in the deployment pod spec is changed (eg. typically image to a new version), so one suggested workaround is to set an env variable in your deployment pod spec (eg. RESTART_)

Then when you've updated your secret/configmap, bump the env value in your deployment (via kubectl apply, or patch, or edit), and Kubernetes will start a rolling update of your deployment.

Example Deployment spec:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-nginx
spec:
  replicas: 2
  template:
    metadata:
    spec:
      containers:
      - name: nginx
        image: "nginx:stable"
        ports:
        - containerPort: 80
        - mountPath: /etc/nginx/conf.d
          name: config
          readOnly: true
        - mountPath: /etc/nginx/auth
          name: tokens
          readOnly: true
        env:
        - name: RESTART_
          value: "13"
      volumes:
        - name: config
          configMap:
            name: test-nginx-config
        - name: tokens
          secret:
            secretName: test-nginx-tokens

Two tips:

  • your environment variable name can't start with an _ or it magically disappears somehow.
  • if you use a number for your restart variable you need to wrap it in quotes
-- rcoup
Source: StackOverflow