将应用程序部署到 Kubernetes 集群时未找到 ConfigMap

bak*_*ops 4 kubernetes

我正在尝试将应用程序部署到 Kubernetes 集群。我的部署使用三个 configMap 作为volumeMount。

但是,当我应用部署时,它似乎找不到 configMaps。

我的部署.yml 如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: dev-space
  name: my-app-dev
spec:
  replicas: 1
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      name: my-app-dev
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 30%
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: my-app-dev
        version: v1
      annotations:
        sla: high
        tier: application
        role: frontend-api
        quality: dev
    spec:
      containers:
      - name: my-app
        env:
        - name: ENVIRONMENT
          value: dev
        - name: SAMPLE_FILE
          value: sample.yml
        - name: SAMPLE_FILE2
          value: sample2.yml
        image: my-app:1.0
        ports:
        - containerPort: 8000
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /health
            port: 9000
          initialDelaySeconds: 11
          timeoutSeconds: 3
        readinessProbe:
          httpGet:
            path: /health
            port: 9000
          initialDelaySeconds: 11
          timeoutSeconds: 3
        volumeMounts:
          - name: sample-volume
            mountPath: /path
            readOnly: true
          - name: sample-volume1
            mountPath: /path1
            readOnly: true
          - name: sample-volume2
            mountPath: /path2
            readOnly: true
      nodeSelector:
        tier: app
      imagePullSecrets:
      - name: img-secret
      volumes:
        - name: "sample-volume"
          configMap:
            name: "sample-volume-dev-my-app"
        - name: "sample-volume1"
          configMap:
            name: "sample-volume1-dev-my-app"
        - name: "sample-volume2"
          configMap:
            name: "sample-volume2-dev-my-app"
Run Code Online (Sandbox Code Playgroud)

当我应用部署时,出现以下错误:

Warning  FailedMount   4m (x6 over 5m)  kubelet, server.org.local  MountVolume.SetUp failed for volume "sample-volume" : configmaps "sample-volume-dev-my-app" not found
Warning  FailedMount   4m (x6 over 5m)  kubelet, server.org.local  MountVolume.SetUp failed for volume "sample-volume1" : configmaps "sample-volume1-dev-my-app" not found
Warning  FailedMount   4m (x6 over 5m)  kubelet, server.org.local  MountVolume.SetUp failed for volume "sample-volume2" : configmaps "sample-volume2-dev-my-app" not found
Run Code Online (Sandbox Code Playgroud)

我的配置有问题吗?可能是什么问题?

Arg*_*dhu 12

您尚未创建配置映射,或者您在与部署应用程序的名称空间不同的名称空间中创建了它们。

kubectl get cm -A
Run Code Online (Sandbox Code Playgroud)

上面的命令将列出所有命名空间中的所有配置映射。检查具有名称的配置映射是否sample-volume-dev-my-app存在以及位于哪个命名空间中。