Required changes to migrate to Kubernetes 1.16

10/1/2019

I have a multi-component platform which I created the required helm charts for it and it was properly working on Kubernetes <= 1.15.

Now I need to prepare them to be compatible with k8s 1.16. I thought that it is just enough to change the extensions/v1beta1 to apps/v1 but after I tried to install the helm charts on k8s I got this error:

Error: release test166 failed: Deployment.apps "bridge-http" is invalid: [spec.selector: Required value, spec.template.metadata.labels: Invalid value: map[string]string{"io.kompose.service":"bridge-http"}: `selector` does not match template `labels`]

And this is my yaml/helm file which works on older k8s:

---
apiVersion: v1
kind: Service
metadata:
  annotations:
    Process: bridge-http
  creationTimestamp: null
  labels:
    io.kompose.service: bridge-http
  name: bridge-http
spec:
  ports:
  - name: "9995"
    port: 9995
    targetPort: 9995
  selector:
    io.kompose.service: bridge-http
status:
  loadBalancer: {}
---
# apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    Process: bridge-http
  creationTimestamp: null
  labels:
    io.kompose.service: bridge-http
  name: bridge-http
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: bridge-http
    spec:
      containers:
      - args:
        - bash
        - -c
        - npm start
        env:
        - name: WWS_BRIDGE_HTTP_BROKER_DATA_USER
          value: {{ .Values.WWS_BRIDGE_HTTP_BROKER_DATA_USER | quote }}
        image: {{ .Values.image }}
        name: bridge-http
        readinessProbe:
          tcpSocket:
            port: 9995
          initialDelaySeconds: 5
          periodSeconds: 15
        ports:
        - containerPort: 9995
        resources:
          requests:
            cpu: 0.1
            memory: 250Mi
          limits:
            cpu: 2
            memory: 5Gi
      restartPolicy: Always
      imagePullSecrets:
      - name: wwssecret
status: {}

I couldn't find anything regarding changes in selectors and lables here: https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/

So why I am getting this error and how I can solve it?

-- AVarf
kubernetes
kubernetes-helm

1 Answer

10/1/2019

It looks like typo in your deployment template:

The matchLabels field is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is “key” the operator is “In”, and the values array contains only “value”. All of the requirements, from both matchLabels and matchExpressions, must be satisfied in order to match.

Shortly: The selector field defines how the Deployment finds which Pods to manage. In this case, you simply select a label that is defined in the Pod template (app: nginx). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.

Inside your Deployment there is missing part:

spec:
  replicas: 1
  selector: # missing part as described by error spec.selector: Required value
    matchLabels:
      io.kompose.service: bridge-http
  template:
    metadata:
      labels:
        io.kompose.service: bridge-http
    spec:
      containers:

Please let me know if this helped.

-- Hanx
Source: StackOverflow