迁移到Kubernetes 1.16所需的更改

问题描述 投票:-2回答:1

我有一个多组件平台,为此我创建了所需的掌舵图,并且它可以在Kubernetes <= 1.15上正常工作。

现在,我需要准备它们以与k8s 1.16兼容。我以为将extensions/v1beta1更改为apps/v1就足够了,但是当我尝试在k8s上安装头盔图表时,出现了此错误:

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/

所以我为什么会收到此错误以及如何解决它?

kubernetes kubernetes-helm
1个回答
0
投票

在您的部署模板中看起来像拼写错误:

matchLabels字段是{key,value}对的映射。 matchLabels映射中的单个{key,value}等同于matchExpressions的元素,其key字段为“ key”,运算符为“ In”,而values数组仅包含“ value”。必须满足matchLabels和matchExpressions的所有要求才能进行匹配。

不久:选择器字段定义了部署如何查找要管理的Pod。在这种情况下,您只需选择在Pod模板(应用程序:nginx)中定义的标签。但是,只要Pod模板本身满足该规则,就可以使用更复杂的选择规则。

Deployment内部缺少部分:

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:

请让我知道是否有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.