一、The connection to the server localhost:8080 was refused - did you specify the right host or port?

问题分析

环境变量
原因:kubernetes master没有与本机绑定,集群初始化的时候没有绑定,此时设置在本机的环境变量即可解决问题。

解决:
步骤一:设置环境变量

  1. ##具体根据情况,此处记录linux设置该环境变量
  2. ll /etc/kubernetes/kubelet.conf
  3. -rw------- 1 root root 1906 1月 15 09:52 /etc/kubernetes/kubelet.conf
  4. ##方式一:编辑文件设置
  5. vim /etc/profile
  6. >>在底部增加新的环境变量 export KUBECONFIG=/etc/kubernetes/kubelet.conf
  7. ##方式二:直接追加文件内容
  8. echo "export KUBECONFIG=/etc/kubernetes/kubelet.conf" >> /etc/profile

步骤二:使生效

source /etc/profile

二、INSTALLATION FAILED: cannot re-use a name that is still in use

#执行helm安装时报错
Error: INSTALLATION FAILED: cannot re-use a name that is still in use

解决:

  1. helm ls --all-namespaces
  2. kubectl delete namespace qsh-test
  3. kubectl create namespace qsh-test

三、Namespace无法删除

unable to create new content in namespace posthog because it is being terminated

现象:

  1. ##命名空间一直处于Terminating状态
  2. [ec2-user@eks posthog]$ kubectl get ns -owide
  3. NAME STATUS AGE
  4. default Active 3d
  5. kube-node-lease Active 3d
  6. kube-public Active 3d
  7. kube-system Active 3d
  8. posthog Terminating 3h23m
  9. ##执行强制删除命令会一直卡住
  10. [ec2-user@eks posthog]$ kubectl delete ns posthog --grace-period=0 --force
  11. warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
  12. \namespace "posthog" force deleted

解决:

  1. ##查看posthog的命名空间描述
  2. kubectl get ns posthog -o json > ns-posthog.json
  3. ##删除spec
  4. ###删除前内容如下:
  5. "spec": {
  6. "finalizers": [
  7. "kubernetes"
  8. ]
  9. },
  10. ###删除后内容如下:
  11. "spec": {
  12. },
  13. ##打开一个新窗口运行kubectl proxy跑一个API代理在本地的8081端口
  14. kubectl proxy --port=8081
  15. ##curl删除
  16. curl -k -H "Content-Type:application/json" -X PUT --data-binary @ns-posthog.json http://127.0.0.1:8081/api/v1/namespaces/posthog/finalize
  17. ##重新检查,发现已删除
  18. kubectl get ns