这是我的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/config
称为 kubeconfig 文件。转到主节点并运行kubectl config view --flatten
并将输出粘贴到~/.kube/config
您的 PC 上,然后尝试从 PC 运行 kubectl。您需要系统中正确的 kubeconfig 文件并设置正确的上下文。要检查当前上下文,请使用此kubectl config current-context
答案2
对我来说,我必须改变背景:
kubectl config use-context <cluster_name>