0

We have a deployed API in Kubernetes. The API is deployed via replication controller to pods and a managing rc. I would like to update the configuration to the API pods using rolling-update. I can do that, however the only way I can get the rolling-update command to not error is by changing the name of the RC. But doing this breaks the link from my Service (exposed as a load balancer) to the RC and it cannot find my pods anymore. Does someone have an example config for updating a replication controller without changing the name?

apiVersion: v1
kind: ReplicationController
metadata:
    name: my-api
    labels:
        name: my-api
spec:
    replicas: 4
    selector:
        name: my-api
    template:
        metadata:
            labels:
                name: my-api
        spec:
            containers:
              - name: my-api
                image: docker-registry.example.com/mynamespace/my-api
                command: [ "sh", "-c", "/do/the/thing/run"]
                resources:
                    limits:
                        cpu: 0
                ports:
                  - name: web
                    containerPort: 80
                env:
                  - name: "HELLO"
                    value: "WORLD"

And I would like, for example to change the env var "HELLO" to "Bob" or something.

3
  • Does someone have an example config for updating a replication controller without changing the name? Could you add the config you are using to try to make it work, i.e. could you add your attempts to solve the issue?
    – 030
    Dec 2, 2015 at 18:23
  • You shouldn't change the name of the RC. All you really need to change is the version and the docker container and issue the rolling update command
    – Mike
    Dec 2, 2015 at 18:58
  • @Mike - I'm trying to just update config so no container version change is necessary
    – four43
    Dec 2, 2015 at 19:11

1 Answer 1

0

So I came up with a strategy that might work. Most of the documentation I was working off of had the Service selector based on the name of the pod. That doesn't work, because the name HAS to change when performing a rolling update. It's best to make the service.spec.selector something like "type=api-server" or some other metadata label then add type=api-server to your pods. (Remember services point at pods directly, not RCs)

Replication Controller:

apiVersion: v1
kind: ReplicationController
metadata:
    name: my-api-{{randomDigits}}
    labels:
        name: my-api-{{randomDigits}}
spec:
    replicas: 4
    selector:
        name: my-api-{{randomDigits}}
    template:
        metadata:
            labels:
                name: my-api-{{randomDigits}}
                type: api-server
        spec:
            containers:
              - name: my-api
                image: docker-registry.example.com/mynamespace/my-api
                command: [ "sh", "-c", "/do/the/thing/run"]
                resources:
                    limits:
                        cpu: 0
                ports:
                  - name: web
                    containerPort: 80
                env:
                  - name: "HELLO"
                    value: "WORLD"

Service:

apiVersion: v1
kind: Service
metadata:
    name: my-api-service
    labels:
        name: my-api-service
spec:
    type: LoadBalancer
    ports:
      - port: 80
    selector:
        type: api-server

Then if you want to update your pod's config, you just change {{randomDigits}} to something new and you can perform a rolling update without breaking the link from your Service to your Pods.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .