Kubernetes Deployment Patch API is not deleting old ReplicaSets

9/11/2018

I am using Kubernets API v1.9 to patch my deployments, but after the patch, the old replicaset are not removed, and I cannot see 'OldReplicaSets' using kubectl describe deploy xxx. I cannot roll back to old versions as well.

Cluster Information

  • IBM ICP v2.1.0.2, Kubernetes V1.9
  • IBM ICP v2.1.0.3, Kubernetes V1.10

Kubectl Version: Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.1", GitCommit:"3a1c9449a956b6026f075fa3134ff92f7d55f812", GitTreeState:"clean", BuildDate:"2018-01-04T11:52:23Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.1+icp-ee", GitCommit:"d97ba3f083461e0ae0a8881550e83350af4c8f57", GitTreeState:"clean", BuildDate:"2018-02-23T07:20:41Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

The API address : https://v1-9.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#patch-22

The API call I made with Postman:

PATCH /apis/apps/v1beta1/namespaces/default/deployments/devops-front HTTP/1.1
Host: ****:8001
Content-Type: application/strategic-merge-patch+json
Cache-Control: no-cache
Postman-Token: 46052a2c-2f3b-48a0-83b9-c70aeb2e5dda

{
    "metadata": {
        "labels": {
            "version":"v1.0.7"
        }
    },
    "spec": {
        "template": {
            "spec": {
                "containers": [{
                    "name": "devops-front",
                    "image": "mycluster.icp:8500/default/devops/devops-front:v1.0.7"
                }]
            },
            "metadata": {
                "labels": {
                    "version": "v1.0.7"
                }
            }
        }
    }
}

The deploy information after the request:

Name:                   devops-front
Namespace:              default
CreationTimestamp:      Tue, 28 Aug 2018 10:07:52 +0800
Labels:                 run=devops-front
                        version=v1.0.0
Annotations:            deployment.kubernetes.io/revision=1
Selector:               run=devops-front,version=v1.0.7
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  run=devops-front
           version=v1.0.7
  Containers:
   devops-front:
    Image:        mycluster.icp:8500/default/devops/devops-front:v1.0.7
    Ports:        80/TCP, 443/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   devops-front-655c4969b4 (3/3 replicas created)
Events:          <none>

I give some more details here

My yaml file: The version label and the tag of the image is automatically refined by code.

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: devops-front
spec:
  replicas: 3
  strategy: 
    type: RollingUpdate
  template:
    metadata:
      labels:
        run: devops-front
        version: v1.0.7
    spec:
      containers:
      - name: devops-front
        image: mycluster.icp:8500/default/devops/devops-front:v1.0.7
        ports:
        - containerPort: 80
        - containerPort: 443  
        imagePullPolicy: Always

When I use the HTTP PATCH API to update my deployment, I get two ReplicaSet:

NAME                                DESIRED   CURRENT   READY     AGE
devops-front-5c4b55bf96             3         3         3         6h
devops-front-c98d99cf6              3         3         3         2d

These two replicasets differs only in the version label and image version. As I described, the old ReplicaSet is not deleted as expected, neither do I see a rolling update process after calling the patch api.

  • Why don't I use replace api?

Because I learned that kubernetes has RollingUpdate feature, and I don't want my application down during the update. I know I could use kubectl set image to change my version, but I also want to change the label. As far as I know, I should use kubectl patch deployments/devops-front ... to make changes. The problem here is that kubectl patch doesn't equal to the patch rest api.

  • Why don't I use kubectl?

Because sometimes I don't have kubectl installed. For example, I want to patch my application in Java code, I could simple acquire a token from the token endpoint and call Kubernetes API or use Fabric8io lib). Another example is that I want to patch my app in Jenkins Pipeline.

  • Why don't I use v1.10 of kubernetes?

I have installed ICP V2.1.0.3 which is based on K8s v1.10, the same problem happens. The ReplicaSet is not automatically deleted when I call patch api.

-- Eden Li
ibm-cloud-private
kubernetes
kubernetes-deployment

0 Answers