跳到主要内容

k8s 问题

问题一

描述

访问 https://127.0.0.1:6443/ui 报错

{
"kind": "Status",
"apiVersion": "v1",
"metadata": {

},
"status": "Failure",
"message": "forbidden: User \"system:anonymous\" cannot get path \"/ui\"",
"reason": "Forbidden",
"details": {

},
"code": 403
}

访问 https://127.0.0.1:6443/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard 报错

{
"kind": "Status",
"apiVersion": "v1",
"metadata": {

},
"status": "Failure",
"message": "services \"kubernetes-dashboard\" is forbidden: User \"system:anonymous\" cannot proxy services in the namespace \"kube-system\"",
"reason": "Forbidden",
"details": {
"name": "kubernetes-dashboard",
"kind": "services"
},
"code": 403
}

解决

访问 k8s dashboard 前需要启动 k8s proxy: 执行kubectl proxy

问题二

描述

启动 kubectl proxy 后访问 http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ 报错

{
"kind": "Status",
"apiVersion": "v1",
"metadata": {

},
"status": "Failure",
"message": "services \"kubernetes-dashboard\" not found",
"reason": "NotFound",
"details": {
"name": "kubernetes-dashboard",
"kind": "services"
},
"code": 404
}

解决

执行 kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml 安装 dashboard

问题三

描述

继续启动 kubectl proxy 后访问 http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ 报错

{
"kind": "Status",
"apiVersion": "v1",
"metadata": {

},
"status": "Failure",
"message": "no endpoints available for service \"https:kubernetes-dashboard:\"",
"reason": "ServiceUnavailable",
"code": 503
}

解决

问题四

描述

执行 kubectl -s http://localhost:8080 run nginx --image=nginx --port=80 报错:error: failed to discover supported resources: yaml: line 22: mapping values are not allowed in this context

解决