設定錯誤:找不到指定上下文的上下文:kind-kind

設定錯誤:找不到指定上下文的上下文:kind-kind

這是我的skaffold.yaml文件:

apiVersion: skaffold/v2alpha3
kind: Config
deploy:
  kubeContext: kind-kind
  kubectl: 
    manifests:
      - ./infra/k8s/*
build:
  local:
    push: false
  artifacts:
    - image: learnertester/auth
      context: auth
      docker:`
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: learnertester/ticketing-client
      context: client
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: '**/*.js'
            dest: .
    - image: learnertester/tickets
      context: tickets
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: learnertester/orders
      context: orders
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: learnertester/expiration
      context: expiration
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: learnertester/payments
      context: payments
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .

當我嘗試時,kubectl config view我得到這個結果:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://192.168.1.2:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: DATA+OMITTED
    client-key-data: DATA+OMITTED

我還安裝kind並創建了一個叢集。這是以下結果kubectl cluster-info --context kind-kind

Kubernetes control plane is running at https://127.0.0.1:41887
CoreDNS is running at https://127.0.0.1:41887/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

但是,當我運行時,skaffold dev最後出現此錯誤:

 - Error in configuration: context was not found for specified context: kind-kind
WARN[0480] deployer cleanup:kubectl delete: exit status 1  subtask=-1 task=DevLoop
unable to connect to Kubernetes: getting client config for Kubernetes client: error creating REST client config for kubeContext "kind-kind": context "kind-kind" does not exist

我嘗試從文件kubeContext: kind中刪除skaffold.yaml並在文件中添加上下文,/.skaffold/config而不是添加上下文,如下所示:

global:
  local-cluster: true
  survey:
    last-prompted: "2022-12-18T12:20:01-08:00"
  collect-metrics: true
  update:
    last-prompted: "2022-12-18T12:30:37-08:00"
kubeContexts: [kind-kind]

但我仍然得到:

WARN[0000] Could not load global Skaffold defaults. Error encounter while unmarshalling the contents of file "/home/a/.skaffold/config"  subtask=-1 task=DevLoop
WARN[0000] error retrieving insecure registries from global config: push/pull issues may exist...  subtask=-1 task=DevLoop
getting run context: getting cluster: unmarshalling global skaffold config: yaml: unmarshal errors:
  line 8: cannot unmarshal !!str `kind-kind` into config.ContextConfig

答案1

skaffold 使用「kubectl」二進位檔案部署到叢集。檢查你的 skaffold yaml。為了存取 Kubernetes 集群,kubectl 使用設定檔。預設設定檔位於~/.kube/configkubeconfig 檔案。轉到主節點並運行kubectl config view --flatten並將輸出貼到~/.kube/config您的 PC 上,然後嘗試從 PC 運行 kubectl。您的系統中需要正確的 kubeconfig 檔案和正確的上下文集。若要檢查目前上下文,請使用此kubectl config current-context

請參考類似SO1 二氧化硫了解更多。

答案2

對我來說,我必須改變上下文:

kubectl config use-context <cluster_name>

相關內容