Kubernetes学习与应用(06)——安装Node节点

1. 安装Kubernetes

# 设置网络参数
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sysctl -p /etc/sysctl.d/k8s.conf

cat > /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter

关闭swap

swapoff -a

vi /etc/fstab

注释swap

# /dev/mapper/cl-swap     swap                    swap    defaults        0 0

执行下面命令

mount -a

echo "KUBELET_EXTRA_ARGS=--fail-swap-on=false" > /etc/sysconfig/kubelet

使用国内源安装

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

yum install -y kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0
systemctl enable kubelet && systemctl start kubelet

systemctl enable kubelet.service

 

3. 将当前节点加入到Kubernetes服务中

在安装好的Worker节点输入Master节点Kubernetes执行初始化时,打印在屏幕中的命令

kubeadm join 192.168.xx.xxx:6443 --token ryotic.bt5ms3fx0tku0gxd \
    --discovery-token-ca-cert-hash sha256:94014c7543fd0ff86a847959e3f8e149691d4665b7dbc1abdf3d28c9c0ebf75d 

命令执行后,检查是否有WARNING或ERROR的提示信息,如果WARNING信息中含有需要执行的命令,可复制直接执行。

 

4. 在Worker节点也启用kubectl服务

修改服务器环境变量

vi /etc/profile

在尾部添加下面配置

export KUBECONFIG=/etc/kubernetes/admin.conf

保存退出后,运行命令,让配置马上生效

source /etc/profile

将Master节点的admin.conf文件同步到Worker

rsync -avz /etc/kubernetes/admin.conf slave1:/etc/kubernetes/

 

5. 检查节点是否添加成功

输入命令(节点添加到Kubernetes中,需要一段时间进行初始化--大约需要等待5分钟左右时间,耐心等待一段时间后就可以看到Ready状态)

kubectl get nodes

状态显示

NAME     STATUS   ROLES    AGE    VERSION
master   Ready    master   106m   v1.17.0
slave1   Ready    <none>   22m    v1.17.0

输入下面命令,可以看到多了两条记录,IP是当前节点服务器的

kubectl get pod --all-namespaces -o wide

详细内容

NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE    IP               NODE     NOMINATED NODE   READINESS GATES
kube-system   coredns-9d85f5447-v9qld          1/1     Running   0          108m   10.244.0.3       master   <none>           <none>
kube-system   coredns-9d85f5447-z22vf          1/1     Running   0          108m   10.244.0.2       master   <none>           <none>
kube-system   etcd-master                      1/1     Running   0          108m   192.168.10.161   master   <none>           <none>
kube-system   kube-apiserver-master            1/1     Running   0          108m   192.168.10.161   master   <none>           <none>
kube-system   kube-controller-manager-master   1/1     Running   0          108m   192.168.10.161   master   <none>           <none>
kube-system   kube-proxy-gn9gv                 1/1     Running   0          108m   192.168.10.161   master   <none>           <none>
kube-system   kube-proxy-zlwln                 1/1     Running   0          24m    192.168.10.165   slave1   <none>           <none>
kube-system   kube-scheduler-master            1/1     Running   0          108m   192.168.10.161   master   <none>           <none>
kube-system   weave-net-szmnd                  2/2     Running   0          24m    192.168.10.165   slave1   <none>           <none>
kube-system   weave-net-v97dl                  2/2     Running   0          91m    192.168.10.161   master   <none>           <none>

 

posted @ 2020-06-09 09:55  AllEmpty  阅读(340)  评论(0编辑  收藏  举报