环境:

操作系统:centos7.4 64
服务器:3台
环境:腾讯云

mster node1 node2 都要操作

修改主机名称:master node1 node2

vim /etc/hosts
master 172.17.0.90
node1  172.17.0.140
node2  172.17.0.9
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness = 0
EOF
sysctl --system
yum install ipset ipvsadm conntrack-tools.x86_64 -y
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
 #!/bin/bash
ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack_ipv4"
for kernel_module in \${ipvs_modules}; do
 /sbin/modinfo -F filename \${kernel_module} > /dev/null 2>&1
 if [ $? -eq 0 ]; then
 /sbin/modprobe \${kernel_module}
 fi
done
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules
sh /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs
systemctl stop firewalld && systemctl disable firewalld
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
sed -i 's/.*swap.*/#&/' /etc/fstab
echo "*/5 * * * * /usr/sbin/ntpdate time.windows.com > /dev/null 2>&1" >> /var/spool/cron/root

安装docker

yum install container-selinux libseccomp libtool-ltdl -y
rpm -ivh https://mirrors.ustc.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm
systemctl start docker && systemctl enable docker
cat > /etc/docker/daemon.json << EOF
{
     "registry-mirrors": ["https://8vtb3cuu.mirror.aliyuncs.com"]
}
EOF
systemctl restart docker

安装kubeadm

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=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install kubelet-1.12.1 -y
yum install kubeadm-1.12.1 -y

master 操作

kubeadm config images list --kubernetes-version v1.12.1
会输入对应的版本 然后改下面的脚本

下面是我自己弄好的脚本 指接下载执行

wget https://raw.githubusercontent.com/ywmack/k8s/master/down-master-images.sh
chmod 755 down-master-images.sh
/bin/bash down-master-images.sh
kubeadm config print-default
wget https://raw.githubusercontent.com/ywmack/k8s/master/kubeadm-config.yaml
systemctl enable kubelet.service

执行Init创建集群

kubeadm init --config kubeadm-config.yaml
最后一行 包含join的输出 记录下来
kubeadm join 172.17.0.90:6443 --token ja8mxt.712olcqi3r3txon4 --discovery-token-ca-cert-hash sha256:a26b65db27c0eb21467c4a3371deb4b0b5b82580f52482c02fc653c98d7f2570

root用户设置环境变量

vim /etc/profile
export KUBECONFIG=/etc/kubernetes/admin.conf
source /etc/profile

添加Pod网络组件

wget https://raw.githubusercontent.com/ywmack/k8s/master/kube-flannel.yml
kubectl apply -f kube-flannel.yml

常用命令

查看集群状态
kubectl get cs
查看节点,pods
kubectl get nodes
kubectl get pods,svc -n kube-system

node节点操作

有几个节点就操作几个
下载镜像

wget https://raw.githubusercontent.com/ywmack/k8s/master/down-node-images.sh
chmod 755 down-node-images.sh
/bin/bash down-node-images.sh

加入群集
执行master最后返回的一行

kubeadm join 172.17.0.90:6443 --token r38v3g.ebvfzkeg00sqfck6 --discovery-token-ca-cert-hash sha256:c3eca73760b232734edf803c8c382dfee23afb5f4fce0d59384820352b7ca90f

问题:

[root@master ~]# kubectl get nodes
NAME     STATUS     ROLES    AGE   VERSION
master   NotReady   master   59m   v1.12.1
node1    NotReady   <none>   21m   v1.12.1
node2    NotReady   <none>   20m   v1.12.1
[root@master ~]#  journalctl -f -u kubelet
-- Logs begin at Tue 2019-04-30 14:33:47 CST. --
Apr 30 15:57:17 master kubelet[6320]: E0430 15:57:17.877196    6320 azure_dd.go:147] failed to get azure cloud in GetVolumeLimits, plugin.host: master
Apr 30 15:57:20 master kubelet[6320]: W0430 15:57:20.455231    6320 cni.go:188] Unable to update cni config: No networks found in /etc/cni/net.d
Apr 30 15:57:20 master kubelet[6320]: E0430 15:57:20.455358    6320 kubelet.go:2167] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
Apr 30 15:57:25 master kubelet[6320]: W0430 15:57:25.456460    6320 cni.go:188] Unable to update cni config: No networks found in /etc/cni/net.d
Apr 30 15:57:25 master kubelet[6320]: E0430 15:57:25.456584    6320 kubelet.go:2167] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
Apr 30 15:57:27 master kubelet[6320]: E0430 15:57:27.885210    6320 azure_dd.go:147] failed to get azure cloud in GetVolumeLimits, plugin.host: master
Apr 30 15:57:30 master kubelet[6320]: W0430 15:57:30.457614    6320 cni.go:188] Unable to update cni config: No networks found in /etc/cni/net.d
Apr 30 15:57:30 master kubelet[6320]: E0430 15:57:30.457736    6320 kubelet.go:2167] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
Apr 30 15:57:35 master kubelet[6320]: W0430 15:57:35.458794    6320 cni.go:188] Unable to update cni config: No networks found in /etc/cni/net.d

解决办法

vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

修改文件内容: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/ --cni-bin-dir=/opt/cni/bin"

systemctl daemon-reload
systemctl restart docker
systemctl restart kubelet

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐