迁移到 Kubernetes 1.16 所需的更改

迁移到 Kubernetes 1.16 所需的更改

我有一个多组件平台,我为其创建了所需的 Helm 图表,并且它在 Kubernetes <= 1.15 上正常运行。

现在我需要准备它们以兼容 k8s 1.16。我以为只需更改为就足够了extensions/v1beta1apps/v1但是在尝试在 k8s 上安装 helm charts 后,我收到了此错误:

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`]

这是我的 yaml/helm 文件,可以在旧版 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: {}

我在这里找不到有关选择器和标签变化的任何信息:https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/

那么为什么我会收到这个错误以及如何解决它?

答案1

作为 1.16 升级的一部分,我们已将 extensions/v1beta1 更改为 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  
  selector:
    matchLabels:
      app: bridge-http

相关内容