0

我想在 Kubernetes 上部署前端和后端应用程序。我写了 yaml 文件(我从 helm 模板得到这个):

# Source: quality-control/templates/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: RELEASE-NAME-quality-control
  labels:
    app.kubernetes.io/name: quality-control
    helm.sh/chart: quality-control-0.1.0
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/managed-by: Tiller
spec:
  rules:
    - host: "quality-control.ru"
      http:
        paths:
          - path: /
            backend:
              serviceName: RELEASE-NAME-quality-control
              servicePort: http

---
# Source: quality-control/templates/deployment.yaml
apiVersion: apps/v1beta2
kind: List
items:
- apiVersion: apps/v1beta2
  kind: Deployment
  metadata:
    name: quality-control-frontend
    labels:
      app.kubernetes.io/name: quality-control-frontend
      helm.sh/chart: quality-control-0.1.0
      app.kubernetes.io/instance: RELEASE-NAME
      app.kubernetes.io/managed-by: Tiller
  spec:
    replicas: 1
    selector:
    matchLabels:
      app.kubernetes.io/name: quality-control-frontend
      app.kubernetes.io/instance: RELEASE-NAME
    template:
      metadata:
        labels:
          app.kubernetes.io/name: quality-control-frontend
          app.kubernetes.io/instance: RELEASE-NAME
        logger: external
        sourcetype: quality-control-frontend
      spec:
        containers:
          - name: quality-control
            image: "registry.***.ru:5050/quality-control-frontend:stable"
            imagePullPolicy: Always
            env:
            - name: spring_profiles_active
              value: dev

            ports:
              - containerPort: 80
                protocol: TCP
                livenessProbe:
                  httpGet:
                    path: /healthcheck
                    port: 80
                    protocol: TCP
                  initialDelaySeconds: 10
                  periodSeconds: 10
            resources:
            limits:
              cpu: 2
              memory: 2048Mi
            requests:
              cpu: 1
              memory: 1024Mi

- apiVersion: apps/v1beta2
  kind: Deployment
  metadata:
    name: quality-control-backend
    labels:
      app.kubernetes.io/name: quality-control-backend
      helm.sh/chart: quality-control-0.1.0
      app.kubernetes.io/instance: RELEASE-NAME
      app.kubernetes.io/managed-by: Tiller
  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: quality-control-backend
        app.kubernetes.io/instance: RELEASE-NAME
    template:
      metadata:
        labels:
          app.kubernetes.io/name: quality-control-backend
          app.kubernetes.io/instance: RELEASE-NAME
          logger: external
          sourcetype: quality-control-backend
      spec:
        containers:
          - name: quality-control
            image: "registry.***.ru:5050/quality-control-backend:stable"
            imagePullPolicy: Always
            env:
            - name: spring_profiles_active
              value: dev

            ports:
              - containerPort: 80
                protocol: TCP
                resources:
            limits:
              cpu: 2
              memory: 2048Mi
            requests:
              cpu: 1
              memory: 1024Mi


---
# Source: quality-control/templates/service.yaml
apiVersion: v1
kind: List
items:
  - apiVersion: v1
    kind: Service
    metadata:
      name: quality-control-frontend
      labels:
        app.kubernetes.io/name: quality-control-frontend
        helm.sh/chart: quality-control-0.1.0
        app.kubernetes.io/instance: RELEASE-NAME
        app.kubernetes.io/managed-by: Tiller
    spec:
      type: ClusterIP
      ports:
      - port: 80
        targetPort: 80
        protocol: TCP
      selector:
        app.kubernetes.io/name: quality-control-frontend
        app.kubernetes.io/instance: RELEASE-NAME

  - apiVersion: v1
    kind: Service
    metadata:
    name: quality-control-backend
    labels:
        app.kubernetes.io/name: quality-control-backend
        helm.sh/chart: quality-control-0.1.0
        app.kubernetes.io/instance: RELEASE-NAME}
        app.kubernetes.io/managed-by: Tiller
    spec:
      type: ClusterIP
      ports:
        - port: 8080
          targetPort: 8080
          protocol: TCP
      selector:
        app.kubernetes.io/name: quality-control-backend
        app.kubernetes.io/instance: RELEASE-NAME

但是部署时出现错误:

Error: release quality-control failed: Deployment.apps "quality-control-frontend" is invalid: [spec.selector: Required value, spec.template.metadata.la                             bels: Invalid value: map[string]string{"app.kubernetes.io/instance":"quality-control", "app.kubernetes.io/name":"quality-control-frontend"}: `selector`                              does not match template `labels`]
4

1 回答 1

1

第一个部署对象存在缩进问题

改变它

spec:
    replicas: 1
    selector:
    matchLabels:
      app.kubernetes.io/name: quality-control-frontend
      app.kubernetes.io/instance: RELEASE-NAME

spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: quality-control-frontend
        app.kubernetes.io/instance: RELEASE-NAME

服务列表也有缩进问题,需要从

- apiVersion: v1
    kind: Service
    metadata:
    name: quality-control-backend
    labels:
        app.kubernetes.io/name: quality-control-backend
        helm.sh/chart: quality-control-0.1.0
        app.kubernetes.io/instance: RELEASE-NAME}
        app.kubernetes.io/managed-by: Tiller

- apiVersion: v1
    kind: Service
    metadata:
      name: quality-control-backend
      labels:
        app.kubernetes.io/name: quality-control-backend
        helm.sh/chart: quality-control-0.1.0
        app.kubernetes.io/instance: RELEASE-NAME
        app.kubernetes.io/managed-by: Tiller
于 2020-05-22T18:33:02.587 回答