kubernetes: Deployment rolling update `maxSurge` and `maxUnavailable` not changed if I don't specify them

What happened?

I have and exists deployment,the first time I apply It with specifying the rollingUpdate like this

  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 20%
    type: RollingUpdate

And then I modify the deployment’s yaml,remove the strategy Setting,according to the default,I think after re-apply the deployment,the maxSurge and maxUnavailable will change to 25%,but after apply I get the deployment with "-o yaml " option,they do not change. Still like this:

  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 20%
    type: RollingUpdate

What did you expect to happen?

After modify the yaml and remove the strategy,and apply it, the deployment in cluster should change the maxSurge and maxUnavailable to 25% according to default.

How can we reproduce it (as minimally and precisely as possible)?

Deploy a deployment with strategy like this

  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 20%
    type: RollingUpdate

then remove the strategy setting from the yaml and apply again

Anything else we need to know?

No response

Kubernetes version

Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.6", GitCommit:"b39bf148cd654599a52e867485c02c4f9d28b312", GitTreeState:"clean", BuildDate:"2022-09-21T13:19:24Z", GoVersion:"go1.18.6", Compiler:"gc", Platform:"darwin/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"24+", GitVersion:"v1.24.6-aliyun.1", GitCommit:"5296768e052ba56e92b5d5bf7b52d33973a34c6f", GitTreeState:"clean", BuildDate:"2023-04-19T06:36:28Z", GoVersion:"go1.18.6", Compiler:"gc", Platform:"linux/amd64"}

Cloud provider

ali cloud

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, …) and versions (if applicable)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

It seems to have been fixed at least v1.27 .

$ kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.27.3
Kustomize Version: v5.0.1
Server Version: v1.27.3

Create Deployment using this manifest and check .spec.strategy field.

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 20%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
$ kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created

$ kubectl get deploy nginx-deployment -o jsonpath='{.spec.strategy}' 
{"rollingUpdate":{"maxSurge":"100%","maxUnavailable":"20%"},"type":"RollingUpdate"}

Next, remove .spec.strategy field and apply it again. .spec.strategy field has been changed.

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  # strategy:
  #   rollingUpdate:
  #     maxSurge: 100%
  #     maxUnavailable: 20%
  #   type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
$ kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment configured

$ kubectl get deploy nginx-deployment -o jsonpath='{.spec.strategy}'
{"rollingUpdate":{"maxSurge":"25%","maxUnavailable":"25%"},"type":"RollingUpdate"}

It seems to have been fixed at least v1.27 .

$ kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.27.3
Kustomize Version: v5.0.1
Server Version: v1.27.3

Create Deployment using this manifest and check .spec.strategy field.

$ kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created

$ kubectl get deploy nginx-deployment -o jsonpath='{.spec.strategy}' 
{"rollingUpdate":{"maxSurge":"100%","maxUnavailable":"20%"},"type":"RollingUpdate"}

Next, remove .spec.strategy field and apply it again. .spec.strategy field has been changed.

$ kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment configured

$ kubectl get deploy nginx-deployment -o jsonpath='{.spec.strategy}'
{"rollingUpdate":{"maxSurge":"25%","maxUnavailable":"25%"},"type":"RollingUpdate"}

thanks for your answer,I will try it later.