【问题标题】:Azure CLI error json: cannot unmarshal array into Go value of type unstructured.detectorAzure CLI 错误 json:无法将数组解组为 unstructured.detector 类型的 Go 值
【发布时间】:2022-01-24 04:28:45
【问题描述】:

我是 Azure Kubernetes 服务的新手。我创建了一个 Azure Kubernetes 集群并尝试在其中部署一些工作负载。 .yaml文件如下

- apiVersion: v1
  kind: Namespace
  metadata:
    name: azure-vote
  spec:
    finalizers:
      - kubernetes
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: azure-vote-back
    namespace: azure-vote
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: azure-vote-back
    template:
      metadata:
        labels:
          app: azure-vote-back
      spec:
        nodeSelector:
          beta.kubernetes.io/os: linux
        containers:
          - name: azure-vote-back
            image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
            env:
              - name: ALLOW_EMPTY_PASSWORD
                value: 'yes'
            resources:
              requests:
                cpu: 100m
                memory: 128Mi
              limits:
                cpu: 250m
                memory: 256Mi
            ports:
              - containerPort: 6379
                name: redis
- apiVersion: v1
  kind: Service
  metadata:
    name: azure-vote-back
    namespace: azure-vote
  spec:
    ports:
      - port: 6379
    selector:
      app: azure-vote-back
- apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: azure-vote-front
    namespace: azure-vote
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: azure-vote-front
    template:
      metadata:
        labels:
          app: azure-vote-front
      spec:
        nodeSelector:
          beta.kubernetes.io/os: linux
        containers:
          - name: azure-vote-front
            image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
            resources:
              requests:
                cpu: 100m
                memory: 128Mi
              limits:
                cpu: 250m
                memory: 256Mi
            ports:
              - containerPort: 80
            env:
              - name: REDIS
                value: azure-vote-back
- apiVersion: v1
  kind: Service
  metadata:
    name: azure-vote-front
    namespace: azure-vote
  spec:
    type: LoadBalancer
    ports:
      - port: 80
    selector:
      app: azure-vote-front

当我通过 Azure CLI 部署此 .yaml 时,它给了我一个验证错误,但没有指出它在哪里?当我运行 kubectl apply -f ./filename.yaml --validate=false 它给出 "cannot unmarshal array into Go value of type unstructured.detector" 错误。但是,当我在 Azure 门户 UI 中运行相同的 yaml 时,它运行时没有任何错误。是否有人可以提及此问题的原因以及如何解决此问题,不胜感激。

【问题讨论】:

标签: azure kubernetes azure-aks azure-cli


【解决方案1】:

我尝试运行您在 Portal 以及 Azure CLI 中提供的代码。它通过添加 YAML codePortal UI 中成功创建,但使用 Azure CLI 我收到了与您相同的错误:

在对您的YAML file 进行一些修改并对其进行验证后,我再次运行了相同的命令,它成功部署在 Azure CLI 中:

YAML 文件:

apiVersion: v1
kind: Namespace
metadata:
  name: azure-vote
spec:
  finalizers:
    - kubernetes
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-vote-back
  namespace: azure-vote
spec:
  replicas: 1
  selector:
    matchLabels:
      app: azure-vote-back
  template:
    metadata:
      labels:
        app: azure-vote-back
    spec:
      nodeSelector:
        "kubernetes.io/os": linux
      containers:
      - name: azure-vote-back
        image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
        env:
        - name: ALLOW_EMPTY_PASSWORD
          value: "yes"
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-back
spec:
  ports:
  - port: 6379
  selector:
    app: azure-vote-back
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-vote-front
  namespace: azure-vote
spec:
  replicas: 1
  selector:
    matchLabels:
      app: azure-vote-front
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      nodeSelector:
        "kubernetes.io/os": linux
      containers:
      - name: azure-vote-front
        image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 80
        env:
        - name: REDIS
          value: "azure-vote-back"
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-vote-front

输出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-23
    • 2018-05-06
    • 2020-04-29
    • 2017-01-06
    • 1970-01-01
    • 2021-01-05
    • 2022-01-12
    • 1970-01-01
    相关资源
    最近更新 更多