1. 工作流程
2. 虚拟机环境准备
如果使用现成的服务器可忽略此步
-
克隆出三台机器 -
网络模式选择桥接, 方便局域网设备访问 -
网络适配器–高级–MAC地址–生成(每台机器点击一次, 避免因克隆导致MAC地址一样) -
配置静态ip
sed -i "s/BOOTPROTO=dhcp/BOOTPROTO=static/" /etc/sysconfig/network-scripts/ifcfg-ens33
uuid=$(uuidgen ens33)
sed -i "s/UUID=.*/UUID=$uuid/g" /etc/sysconfig/network-scripts/ifcfg-ens33
echo IPADDR=192.169.8.3 >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo GATEWAY=192.169.1.1 >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo NETMASK=255.255.0.0 >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo NM_CONTROLLED=no >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo DNS1=114.114.114.114 >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo DNS2=8.8.8.8 >> /etc/sysconfig/network-scripts/ifcfg-ens33
service network restart
-
配置主机名及hosts
hostnamectl set-hostname k8s-n-1
sed -i 's/localhost.localdomain/k8s-n-1/g' /etc/hosts
reboot
hostnamectl set-hostname k8s-n-2
sed -i 's/localhost.localdomain/k8s-n-2/g' /etc/hosts
reboot
hostnamectl set-hostname k8s-n-3
sed -i 's/localhost.localdomain/k8s-n-3/g' /etc/hosts
reboot
-
检测网络环境是否正常 ping www.baidu.com
3. 部署集群
无特殊说明下述命令需在所有机器分别执行
3.1 准备工作
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
sed -ri 's/.*swap.*/#&/' /etc/fstab
swapoff -a
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
yum install ntpdate -y
ntpdate time.windows.com
3.2 安装docker
yum install -y wget
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum install -y docker-ce
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<- EOF
{
"registry-mirrors":["https://hub-mirror.c.163.com/"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl enable docker.service
systemctl start docker.service
3.3 安装kubeadm, kubelet, kubectl
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=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
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet.service
systemctl start kubelet.service
3.4 部署集群
在要作为master的机器上执行, 此处我在192.169.8.1上执行下述命令
kubeadm init \
--apiserver-advertise-address=192.169.8.1 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.2.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
安时遇到镜像coredns:v1.8.4从阿里云服务器上拉取不到的问题
发现是此镜像在阿里云仓库里tag是coredns:1.8.4, 导致使用v1.8.4拉取不到
解决方案是我们手动拉取此镜像并手动打一个与需求一致的tag
kubeadm config images list
docker images
docker pull registry.aliyuncs.com/google_containers/coredns:1.8.4
docker tag registry.aliyuncs.com/google_containers/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4
docker rmi registry.aliyuncs.com/google_containers/coredns:1.8.4
在其余节点执行init返回的join命令
kubeadm join 192.169.8.1:6443 --token d07ihy.6p9zjow80lh7fklz \ --discovery-token-ca-cert-hash sha256:af7a6897afbfcdca6e46d4595ccb9cc28c0d1ed4141120c76cb18156a2641752
3.5 验证集群状态
3.5.1 节点信息查看
3.5.2 系统pod查看
3.6 配置
3.6.1 命令自动补全
yum install -y bash-completion
|