Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

service label mismatches selector, which result in inconsistency #360

Open
@konnase

Description

@konnase

Service label is app: pytorch-operator, while selector is name: pytorch-operator. Deployment spec label and selector are both name: pytorch-operator.

image

In such a case, both the service and deployment have been deployed via kubectl create -f manifests/base. Then we want to update the operator image, but now we need to run kubectl apply -k manifests/overlays/latest. kustomize will add all the labels of service to selector, as shown below:

$ kustomize build manifests/overlays/latest
apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/path: /metrics
    prometheus.io/port: "8443"
    prometheus.io/scrape: "true"
  labels:
    app: pytorch-operator
  name: pytorch-operator
  namespace: phx-system
spec:
  ports:
  - name: monitoring-port
    port: 8443
    targetPort: 8443
  selector:
    app: pytorch-operator
    name: pytorch-operator
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: pytorch-operator
  name: pytorch-operator
  namespace: phx-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pytorch-operator
      name: pytorch-operator
  template:
    metadata:
      labels:
        app: pytorch-operator
        name: pytorch-operator
    spec:
      containers:
        command:
        - /pytorch-operator.v1
        - --alsologtostderr
        - -v=1
        - --monitoring-port=8443
        env:
        - name: KUBEFLOW_NAMESPACE
          value: kubeflow
        image: ${pytorch-operator-image}
        name: pytorch-operator
      serviceAccountName: pytorch-operator

Then the following error occurs:

$ kubectl apply -k manifests/overlays/latest
serviceaccount/pytorch-operator unchanged
clusterrole.rbac.authorization.k8s.io/pytorch-operator unchanged
clusterrolebinding.rbac.authorization.k8s.io/pytorch-operator unchanged
service/pytorch-operator configured
The Deployment "pytorch-operator" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"pytorch-operator", "name":"pytorch-operator"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Better to match service labels with selectors and deployment's labels and selectors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions