安装docker
删除已安装的docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
11.png
配置阿里云docker 源
# Set up repository
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Use Aliyun Docker
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker
-
安装docker
yum install docker-ce
-
检查安装
image.png
-
启动docker
systemctl start docker
-
设置开机启动
systemctl enable docker
安装 kubeadm, kubelet and kubectl
- 设置阿里云镜像
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
-
Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
-
安装
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
-
检查版本
image.png
-
设置开机启动
systemctl enable --now kubelet
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
- 关闭防火墙
systemctl disable firewalld
- 关闭内存交换
swapoff -a
注释/etc/fstab
最后一行
使用kubeadm启动集群
-
修改主机名称
/etc/hostname
-
初始化集群
kubeadm init
, 被墙了,拉取不了所需要的镜像 -
查看所需要的镜像
image.pngkubeadm config images list
-
绕道阿里云下载(保存为shell执行) 参考 https://my.oschina.net/u/2306127/blog/1843053
echo ""
echo "=========================================================="
echo "Pull Kubernetes v1.14.2 Images from aliyuncs.com ......"
echo "=========================================================="
echo ""
MY_REGISTRY=registry.cn-hangzhou.aliyuncs.com/openthings
## 拉取镜像
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.14.2
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.14.2
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.14.2
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.14.2
docker pull ${MY_REGISTRY}/k8s-gcr-io-etcd:3.3.10
docker pull ${MY_REGISTRY}/k8s-gcr-io-pause:3.1
docker pull ${MY_REGISTRY}/k8s-gcr-io-coredns:1.3.1
## 添加Tag
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.14.2 k8s.gcr.io/kube-apiserver:v1.14.2
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.14.2 k8s.gcr.io/kube-scheduler:v1.14.2
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.14.2 k8s.gcr.io/kube-controller-manager:v1.14.2
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.14.2 k8s.gcr.io/kube-proxy:v1.14.2
docker tag ${MY_REGISTRY}/k8s-gcr-io-etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag ${MY_REGISTRY}/k8s-gcr-io-pause:3.1 k8s.gcr.io/pause:3.1
docker tag ${MY_REGISTRY}/k8s-gcr-io-coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
## 移除镜像
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.14.2
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.14.2
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.14.2
docker rmi ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.14.2
docker rmi ${MY_REGISTRY}/k8s-gcr-io-etcd:3.3.10
docker rmi ${MY_REGISTRY}/k8s-gcr-io-pause:3.1
docker rmi ${MY_REGISTRY}/k8s-gcr-io-coredns:1.3.1
echo ""
echo "=========================================================="
echo "Pull Kubernetes v1.14.2 Images FINISHED."
echo "into registry.cn-hangzhou.aliyuncs.com/openthings, "
echo " by openthings@https://my.oschina.net/u/2306127."
echo "=========================================================="
echo ""
- 查看集群所需要的镜像
docker iamges
-
再次初始化
image.pngkubeadm init
-
初始化成功,注意箭头所在命令,依次执行,否则无法连接kube-apiserver
image.png -
当前节点状态为 NotReady,查看系统日志
image.pngjournalctl -xeu kubelet
-
安装pod网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml
-
重启kubelet
systemctl restart kubelet
-
查看节点状态
image.pngkubectl get nodes
网友评论