Azure CLI 错误 json : cannot unmarshal array into Go value of type unstructured. 检测器

标签 azure kubernetes azure-aks azure-cli

我是 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 时,它​​给出了 “无法将数组解码为 unstructed. detectoror 类型的 Go 值” 错误。但是,当我在 Azure 门户 UI 中运行相同的 yaml 时,它运行时没有任何错误。如果有人能提及此问题的原因以及如何解决此问题,我们将不胜感激。

最佳答案

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

enter image description here

在对 YAML 文件进行一些修改并验证它后,我再次运行相同的命令,它成功部署在 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

输出:

enter image description here

enter image description here

enter image description here

enter image description here

关于Azure CLI 错误 json : cannot unmarshal array into Go value of type unstructured. 检测器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70457670/

相关文章:

c# - 标签在 Azure.Messaging.ServiceBus.ServiceBus.ServiceBusMessage 中不可用

javascript - Azure 移动服务 HTML 5 用户身份验证在 IE(.NET 后端)中显示 Windows 安全对话框

kubernetes - 从镜头中删除Kubernetes集群设置

kubernetes - 如何更改 kubernetes 节点的名称

Azure 模板对 AKS 节点池的支持

Azure kubernetes - Nginx Controller 的数量?

azure - 如何使用 AKS 挂载本地卷 hostPath?

java - Azure Function BlobTrigger : Microsoft. WindowsAzure.Storage:无法建立连接,因为目标计算机主动拒绝它

azure - Azure 数据同步的外键引用错误

docker - 无法使用 kubectl 启动容器