Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply can't work, but delete/apply work #86463

Closed
ozbillwang opened this issue Dec 20, 2019 · 8 comments
Closed

apply can't work, but delete/apply work #86463

ozbillwang opened this issue Dec 20, 2019 · 8 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/apps Categorizes an issue or PR as relevant to SIG Apps.

Comments

@ozbillwang
Copy link

ozbillwang commented Dec 20, 2019

What happened:

when apply a replicaset change, and change the label and apply again, it reports error, I have to delete this replicaset and apply again, all fine.

Furtherly, if the first deployment with wrong yaml, and apply with correct one, it only starts one pod.

What you expected to happen:

should be fine to switch the label and start the nominated count of replica pods.

How to reproduce it (as minimally and precisely as possible):

master $ cat replicaset-definition-1.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-1
spec:
  replicas: 2
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx

master $ kubectl apply -f replicaset-definition-1.yaml
replicaset.apps/replicaset-1 created

master $ kubectl get all
NAME                     READY   STATUS    RESTARTS   AGE
pod/replicaset-1-g97dd   1/1     Running   0          2m7s
pod/replicaset-1-q5b85   1/1     Running   0          2m7s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   25m

NAME                           DESIRED   CURRENT   READY   AGE
replicaset.apps/replicaset-1   2         2         2       2m7s
master $

# So I change the label from `frontend` to `nginx` and apply the change, get error
master $ vi replicaset-definition-1.yaml
master $ cat replicaset-definition-1.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-1
spec:
  replicas: 2
  selector:
    matchLabels:
      tier: nginx
  template:
    metadata:
      labels:
        tier: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
master $ kubectl apply -f replicaset-definition-1.yaml
The ReplicaSet "replicaset-1" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"tier":"nginx"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable
master $

sometime, if previous yaml file is not correct and I apply a proper yml later, I can see the replicaset is created, but only run with one pod. which I need 2 replica pods.

Anything else we need to know?:

Environment: linux

  • Kubernetes version (use kubectl version):
master $ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release):
master $ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
master $
  • Kernel (e.g. uname -a):

master $ uname -a
Linux master 4.4.0-166-generic #195-Ubuntu SMP Tue Oct 1 09:35:25 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:
@ozbillwang ozbillwang added the kind/bug Categorizes issue or PR as related to a bug. label Dec 20, 2019
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Dec 20, 2019
@k8s-ci-robot
Copy link
Contributor

@ozbillwang: The label(s) sig/labels cannot be applied, because the repository doesn't have them

In response to this:

/sig labels

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ozbillwang
Copy link
Author

@kubernetes/sig-cli-bugs

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 20, 2019
@k8s-ci-robot
Copy link
Contributor

@ozbillwang: Reiterating the mentions to trigger a notification:
@kubernetes/sig-cli-bugs

In response to this:

@kubernetes/sig-cli-bugs

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

@ozbillwang: The label(s) sig/labels cannot be applied, because the repository doesn't have them

In response to this:

/sig labels

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@liggitt
Copy link
Member

liggitt commented Dec 20, 2019

The selector on an apps/v1 replicaset is immutable after creation.

/remove-sig cli
/sig apps

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed sig/cli Categorizes an issue or PR as relevant to SIG CLI. labels Dec 20, 2019
@zhouya0
Copy link
Contributor

zhouya0 commented Dec 20, 2019

As it said field is immutable, so you can use kubectl apply --force which will delete and then create.

@tedyu
Copy link
Contributor

tedyu commented Dec 20, 2019

See #66602

@ozbillwang
Copy link
Author

Thanks a lot @zhouya0 & @tedyu

so kubectl apply --force fixed both issue.

  • I can switch label whatever I like to, the command will be always successful
  • I can guarantee to get proper number of replica pods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/apps Categorizes an issue or PR as relevant to SIG Apps.
Projects
None yet
Development

No branches or pull requests

5 participants