解决kubectl 8080 was refused和x509: certificate signed by unknown authority的问题

文章目录

  • 解决kubectl 8080 was refused和x509: certificate signed by unknown authority的问题
    • 错误
    • 在Master上的解决方案
    • 在Node上的解决方案
    • 参考文档

解决kubectl 8080 was refused和x509: certificate signed by unknown authority的问题

错误

未指定API Server报错:

[root@k8s-node1 kubeadm_v1.13.0]# kubectl get pods --all-namespaces
The connection to the server localhost:8080 was refused - did you specify the right host or port?

指定API Server后报错:

[root@k8s-node1 kubeadm_v1.13.0]# kubectl get pods --all-namespaces -s https://192.168.87.152:6443
Unable to connect to the server: x509: certificate signed by unknown authority

在Master上的解决方案

mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
cp -p $HOME/.bash_profile $HOME/.bash_profile.bak$(date '+%Y%m%d%H%M%S')
echo "export KUBECONFIG=$HOME/.kube/config" >> $HOME/.bash_profile
source $HOME/.bash_profile

测试:

kubectl get nodes
kubectl get pods --all-namespaces

在Node上的解决方案

和Master上的方案的区别是使用/etc/kubernetes/kubelet.conf而不是/etc/kubernetes/admin.conf

mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/kubelet.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
cp -p $HOME/.bash_profile $HOME/.bash_profile.bak$(date '+%Y%m%d%H%M%S')
echo "export KUBECONFIG=$HOME/.kube/config" >> $HOME/.bash_profile
source $HOME/.bash_profile

测试:

kubectl get nodes
kubectl get pods --all-namespaces

参考文档

  • https://github.com/kubernetes/kubernetes/issues/48378

你可能感兴趣的:(Kubernetes)