1.系统初始化
systemctl stop firewalld #关闭防火墙
setenforce 0 #关闭selinux
swapoff -a #关闭swap
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF #将桥接的IPV4流量传递到iptables 的链
sysctl --system
安装docker
curl -fsSL https://get.docker.com |bash
systemctl enable docker
systemctl start docker
部署
配置k8s yum源
cat >/etc/yum.repos.d/kubernetes.repo << EOF
[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
安装kubeadm,kubelet和kubectl(直接指定版本安装)
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
初始化初始化kubeadm
kubeadm init \
--apiserver-advertise-address=192.168.149.144 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
记录下node加入集群的命令
kubeadm join 192.168.149.144:6443 --token t1mede.eggih8e8e9zitj2g \
--discovery-token-ca-cert-hash sha256:7da58fded822e1a8710827024979ba3afb7287e781c16728cff0569ba34ada95
拷贝kubectl使用的连接k8s认证文件到默认路径,根据init时的提示执行如下指令
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
执行kubectl get nodes查看状态
[root@localhost ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
localhost.localdomain NotReady master 33m v1.18.0