1. 程式人生 > >k8s V1.11.1報錯:The connection to the server localhost:8080 was refused

k8s V1.11.1報錯:The connection to the server localhost:8080 was refused

問題描述:

# 安裝flannel外掛時報錯
[email protected]:~# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
unable to recognize "https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused

在沒有配置config檔案時,kube-apiserver預設使用的是localhost,解決方法如下:
普通使用者執行如下操作:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

或者以root使用者執行,匯入環境變數:

export KUBECONFIG=/etc/kubernetes/admin.conf

重啟 kubectl 服務