版权声明:本文为博主原创文章。
一、node节点处于NotReady
在master节点查询nodes时出现:
The connection to the server 192.168.200.129:6443 was refused - did you specify the right host or port?
[root@master ~]# kubectl get nodes
The connection to the server 192.168.200.129:6443 was refused - did you specify the right host or port?
1,重启daemon、docker和kuberlet
[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl restart docker
[root@master ~]# systemctl restart kubelet
[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 21h v1.15.3
node01 NotReady 18h v1.15.3
node02 NotReady 18h v1.15.3
node03 NotReady 18h v1.15.3
2,在node节点配置kubectl、kubeadm、kubelet
将master中的kubernetes.repo复制到其他节点
[root@master yum.repos.d]# scp /etc/yum.repos.d/kubernetes.repo node01:/etc/yum.repos.d/kubernetes.repo
[root@master yum.repos.d]# scp /etc/yum.repos.d/kubernetes.repo node02:/etc/yum.repos.d/kubernetes.repo
[root@master yum.repos.d]# scp /etc/yum.repos.d/kubernetes.repo node03:/etc/yum.repos.d/kubernetes.repo
安装kubectl、kubeadm、kubelet
[root@node02 ~]# yum install -y kubeadm kubelet
3,重启各node节点的daemon、docker和kuberlet
[root@node02 ~]# systemctl daemon-reload
[root@node02 ~]# systemctl restart docker
[root@node02 ~]# systemctl restart kubelet
当在node节点查询nodes时出现:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
此时需要配置文件,首先创建隐藏文件:
[root@node03 ~]# mkdir .kube
[root@node03 ~]# ll -a
总用量 28
dr-xr-x---. 4 root root 160 9月 19 09:23 .
dr-xr-xr-x. 17 root root 224 9月 17 01:32 ..
-rw-------. 1 root root 1423 9月 17 01:34 anaconda-ks.cfg
-rw-------. 1 root root 2412 9月 18 20:45 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
drwxr-xr-x 2 root root 6 9月 19 09:23 .kube
drwxr----- 3 root root 19 9月 17 15:55 .pki
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
将master节点的admin.conf复制到其他节点
[root@master ~]# scp /etc/kubernetes/admin.conf node01:/root/.kube/config
[root@master ~]# scp /etc/kubernetes/admin.conf node02:/root/.kube/config
[root@master ~]# scp /etc/kubernetes/admin.conf node03:/root/.kube/config
查看node状态
[root@node03 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 22h v1.15.3
node01 Ready 19h v1.15.3
node02 Ready 19h v1.15.3
node03 Ready 19h v1.15.3
此时node节点的NotReady状态全都转正Ready。
二、宿主机相互交互
创建一个deployment
[root@master ~]# kubectl create deployment jh --image=nginx:1.14-alpine
deployment.apps/jh created
创建一个service,且名字与前面deployment的一致
[root@master ~]# kubectl create svc nodeport jh --tcp=80:80
service/jh created
查看service
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jh NodePort 10.103.2.170 80:31153/TCP 58s