kubernetes pod deployment not updating

7/12/2021

I have a pod egress-operator-controller-manager created from makefile by command make deploy IMG=my_azure_repo/egress-operator:v0.1. enter image description here

This pod was showing unexpected status: 401 Unauthorized error in description, so I created imagePullSecrets and trying to update this pod with secret by creating pod's deployment.yaml egress-operator-manager.yaml file. <br/>But when I am applying this yaml file its giving below error:

root@Ubuntu18-VM:~/egress-operator# kubectl apply -f /home/user/egress-operator-manager.yaml
The Deployment "egress-operator-controller-manager" is invalid: spec.selector: Invalid value:
 v1.LabelSelector{MatchLabels:map[string]string{"moduleId":"egress-operator"}, 
MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

egress-operator-manager.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: egress-operator-controller-manager
  namespace: egress-operator-system
  labels:
    moduleId: egress-operator
spec:
  replicas: 1
  selector:
    matchLabels:
      moduleId: egress-operator
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        moduleId: egress-operator
    spec:
      containers:
        - image: my_azure_repo/egress-operator:v0.1
          name: egress-operator
      imagePullSecrets:
        - name: mysecret

Can somene let me know that how can I update this pod's deployment.yaml ?

-- solveit
azure-container-registry
kubernetes
kubernetes-deployment
kubernetes-pod
makefile

1 Answer

7/12/2021

Delete the deployment once and try applying the YAML agian.

it could be due to K8s service won't allow the rolling update once deployed the label selectors of K8s service can not be updated until you decide to delete the existing deployment

Changing selectors leads to undefined behaviors - users are not expected to change the selectors

https://github.com/kubernetes/kubernetes/issues/50808

-- Harsh Manvar
Source: StackOverflow