当我按照kubernetes的教程进行操作时,出现[错误:json:未知字段“元数据”]错误

时间:2019-06-29 13:50:55

标签: kubernetes configmap

我遵循了本教程https://kubernetes.io/docs/tutorials/configuration/configure-redis-using-configmap/

尝试创建吊舱时出现以下错误

kubectl apply -k .
error: json: unknown field "metadata"

我的kubectl版本如下:

kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:40:16Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.3", GitCommit:"5e53fd6bc17c0dec8434817e69b04a25d8ae0ff0", GitTreeState:"clean", BuildDate:"2019-06-06T01:36:19Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}

下面是我在旅游之后创建的一些文件。

kustomization.yaml

configMapGenerator:
- name: example-redis-config
  files:
  - redis-config
apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis:5.0.4
    command:
      - redis-server
      - "/redis-master/redis.conf"
    env:
    - name: MASTER
      value: "true"
    ports:
    - containerPort: 6379
    resources:
      limits:
        cpu: "0.1"
    volumeMounts:
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf
resources:
- redis-pod.yaml

redis-config

maxmemory 2mb
maxmemory-policy allkeys-lru

redis-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis:5.0.4
    command:
      - redis-server
      - "/redis-master/redis.conf"
    env:
    - name: MASTER
      value: "true"
    ports:
    - containerPort: 6379
    resources:
      limits:
        cpu: "0.1"
    volumeMounts:
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf

有帮助吗?

1 个答案:

答案 0 :(得分:1)

我认为您误解了kustomization.yaml指令(这令人困惑)。您无需将pods/config/redis-pod.yaml的内容添加到kustomization.yaml。您只需下载该文件并添加resources代码段即可。

生成的kustomization.yaml应该看起来像:

configMapGenerator:
- name: example-redis-config
  files:
  - redis-config
resources:
- redis-pod.yaml