尝试使用 kubectl 在命名空间中创建 pod 时出错

问题描述 投票:0回答:1

我是 Kubernetes 新手,我正在尝试在命名空间内创建一个 pod。

我有以下名称sapce.yaml:

apiVersion: v1
kind: Namespace
metadata:
   name: swirlai

以下 configMap.yaml 为:

apiVersion: v1
kind: ConfigMap
metadata:
   name: config
   namespace: swirlai
data:
   enviroment: dev # Key - Value
   db-host: localhost # Key - Value
   airflow.cfg:
    dags_folder = ../CodeExample/airflow/dags
    base_log_folder = ../CodeExample/airflow/logs

secret.yaml 是:

apiVersion: v1
kind: Secret
metadata:
  name: secret
  namespace: swirlai
data:
  secret-data: c3VwZXItc2VjcmV0

pod.yaml 是:

apiVersion: v1
kind: Pod
metadata:
  name: swirlai-pod
  namespace: swirlai
spec:
  containers:
  - name: swirlai-container
    image: nginx:latest
    ports:
    - containerPort: 80
    env:
    - name: DIRECT
      value: Some String
    - name: ENVIRONMENT
      valueFrom:
         configMapKeyRef:
           name: config
           key: dev
    - name: SECRET_DATA
      valueFrom:
         secretKeyRef:
           name: secret
           key: secret-data

运行“kubectl apply -f pod.yaml”命令后,我可以看到命令“describe pod -n swirlai”出现错误

错误是:

错误:在 ConfigMap swirlai/config 中找不到关键环境

kubernetes namespaces
1个回答
0
投票

pod.yaml
文件中,configMapKeyRef.key下不应该是
dev
,应该是
environment

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