使用kubectl 命令是报错
报错:
[root@k8s-master ~]# kubectl get pod The connection to the server localhost:8080 was refused - did you specify the right host or port?
原因: 由于使用kubeadm安装的k8s ,所以需要使用 kubernetes-admin 来运行。
解决方法: (如果admin.conf没有就从k8s-master上copy一份到当前节点)
[root@k8s-master ~]# export KUBECONFIG=/etc/kubernetes/admin.conf [root@k8s-master ~]# kubectl get pod No resources found. [root@k8s-master ~]# kubectl get node NAME STATUS ROLES AGE VERSION k8s-master Ready master 46h v1.14.0 [root@k8s-master ~]#
#也可以编辑 ~/.bash_profile,, 如果使用的是 zsh 那就编辑 ~/.zshrc
添加内容
export KUBECONFIG=/etc/kubernetes/admin.conf
使其生效
source ~/.bash_profile 如果是zsh source ~/.zshrc
用kubeadm 增加节点的方法::有时 忘记token 或 token过期,以及查看 --discovery-token-ca-cert-hash 的方法
#查看当前存在的token [root@k8s-master testnginx]# kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS uf2c4g.n7ibf1g8gxbkqz2z 22h 2019-04-03T15:28:40+08:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token #生成新的token [root@k8s-master testnginx]# kubeadm token create hpvhe4.rbapeoum7utj55cr #再次查看已有的token 发现多了一个 [root@k8s-master testnginx]# kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS hpvhe4.rbapeoum7utj55cr 23h 2019-04-03T16:41:06+08:00 authentication,signing <none> system:bootstrappers:kubeadm:default-node-token uf2c4g.n7ibf1g8gxbkqz2z 22h 2019-04-03T15:28:40+08:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token #查看 --discovery-token-ca-cert-hash 方法 [root@k8s-master testnginx]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' f01892c96cee8d02c373e34bed3a45c8f3f9888fdd19767e706ec09e8fb9c893 #由于我是用来测试 所以删掉这个token [root@k8s-master testnginx]# kubeadm token delete hpvhe4.rbapeoum7utj55cr bootstrap token with id "hpvhe4" deleted #查看token是否删除成功 [root@k8s-master testnginx]# kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS uf2c4g.n7ibf1g8gxbkqz2z 22h 2019-04-03T15:28:40+08:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token [root@k8s-master testnginx]#
node节点反复安装报错
报错: cni.go:259] Error adding network: failed to set bridge addr: "cni0" already has an IP address different from 10.16.2.1/24
解决:在Node上执行如下操作:重置kubernetes服务,重置网络。删除网络配置,link
kubeadm reset systemctl stop kubelet systemctl stop docker rm -rf /var/lib/cni/ rm -rf /var/lib/kubelet/* rm -rf /etc/cni/ ifconfig cni0 down ifconfig flannel.1 down ifconfig docker0 down ip link delete cni0 ip link delete flannel.1
qingfeng