swap
自 K8S 1.8 开始,启动 kubelet 时,需要禁用 swap 。或者需要更改 kubelet 的启动参数 --fail-swap-on=false
[root@centos ~]# swapoff -a
即重启后也生效
[root@centos ~]# sed -i.bak '/swap/s/^/#/' /etc/fstab
free
命令验证一下
[root@centos ~]# free
total used free shared buff/cache available
Mem: 3880248 151592 3536904 8712 191752 3508152
Swap: 0 0 0
默认主机名为centos,修改后方便辨认主机在集群中对应角色
[root@centos ~]# hostnamectl set-hostname master01
[root@centos ~]# cat /etc/hostname
master01
能ping通外网跳过这一步
[root@centos ~]# vi /etc/resolv.conf
nameserver 8.8.8.8
由于使用了flannel
,所以需要修改网络设置
[root@master01 ~]# cat /proc/sys/net/bridge/bridge-nf-call-iptables
0
修改为1
sysctl net.bridge.bridge-nf-call-iptables=1
已安装可以跳过
[root@master01 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@master01 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
列出可用的docker版本
[root@master01 ~]# yum list docker-ce --showduplicates | sort -r
输出
[root@master01 ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
可安装的软件包
* updates: mirrors.bfsu.edu.cn
Loading mirror speeds from cached hostfile
* extras: mirrors.huaweicloud.com
docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
安装docker-ce
docker-cli
,这边选择相对稳定的18.09.9
[root@master01 ~]# yum install docker-ce-18.09.9 docker-ce-cli-18.09.9 containerd.io -y
设置Docker自启
[root@master01 ~]# systemctl start docker && systemctl enable docker
方便安装kubectl
, kubeadm
, kubelet
三个组件
[root@master01 ~]# cat < /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
刷新源
[root@master01 ~]# yum clean all
[root@master01 ~]# yum -y makecache
[root@master01 ~]# yum list kubelet --showduplicates | sort -r
kubelet.x86_64 1.17.9-0 kubernetes
kubelet.x86_64 1.17.8-0 kubernetes
kubelet.x86_64 1.17.7-1 kubernetes
kubelet.x86_64 1.17.7-0 kubernetes
kubelet.x86_64 1.17.6-0 kubernetes
kubelet.x86_64 1.17.5-0 kubernetes
kubelet.x86_64 1.17.4-0 kubernetes
kubelet.x86_64 1.17.3-0 kubernetes
kubelet.x86_64 1.17.2-0 kubernetes
kubelet.x86_64 1.17.11-0 kubernetes
kubelet.x86_64 1.17.1-0 kubernetes
kubelet.x86_64 1.17.0-0 kubernetes
kubelet.x86_64 1.16.9-0 kubernetes
kubelet.x86_64 1.16.8-0 kubernetes
kubelet.x86_64 1.16.7-0 kubernetes
kubelet.x86_64 1.16.6-0 kubernetes
kubelet.x86_64 1.16.5-0 kubernetes
kubelet.x86_64 1.16.4-0 kubernetes
kubelet.x86_64 1.16.3-0 kubernetes
kubelet.x86_64 1.16.2-0 kubernetes
kubelet.x86_64 1.16.15-0 kubernetes
kubelet.x86_64 1.16.14-0 kubernetes
kubelet.x86_64 1.16.13-0 kubernetes
kubelet.x86_64 1.16.12-0 kubernetes
kubelet.x86_64 1.16.11-1 kubernetes
kubelet.x86_64 1.16.11-0 kubernetes
kubelet.x86_64 1.16.1-0 kubernetes
kubelet.x86_64 1.16.10-0 kubernetes
kubelet.x86_64 1.16.0-0 kubernetes
kubelet.x86_64 1.15.9-0 kubernetes
kubelet.x86_64 1.15.8-0 kubernetes
kubelet.x86_64 1.15.7-0 kubernetes
kubelet.x86_64 1.15.6-0 kubernetes
kubelet.x86_64 1.15.5-0 kubernetes
kubelet.x86_64 1.15.4-0 kubernetes
kubelet.x86_64 1.15.3-0 kubernetes
kubelet.x86_64 1.15.2-0 kubernetes
kubelet.x86_64 1.15.12-0 kubernetes
kubelet.x86_64 1.15.11-0 kubernetes
kubelet.x86_64 1.15.1-0 kubernetes
kubelet.x86_64 1.15.10-0 kubernetes
安装kubelet
, kubeadm
, kubectl
,选择1.16.15
版本,从kubernetes GitHub主页得知,1.16支持Docker18.09
[root@master01 ~]# yum install -y kubelet-1.16.15 kubeadm-1.16.15 kubectl-1.16.15
设置kubelet
开机启动
[root@master01 ~]# systemctl enable kubelet && systemctl start kubelet
安装API Server
, Controller Manager
, Scheduler
, proxy
, pause
, etcd
, coredns
服务组件,这些服务本身也从Docker镜像构建。
由于Docker镜像服务器在境外,直接拉取镜像存在网络问题,这边采用从阿里云拉取镜像,拉取到本地后将镜像改为原来的tag的方式。
即:
docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.16.15
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.16.15 k8s.gcr.io/kube-apiserver:v1.16.15
由于组件过多,因此使用脚本
来完成。
[root@master01 ~]# vi image.sh
#!/bin/bash
url=registry.aliyuncs.com/google_containers
version=v1.16.15
images=(`kubeadm config images list --kubernetes-version=$version|awk -F '/' '{print $2}'`)
for imagename in ${images[@]} ; do
docker pull $url/$imagename
docker tag $url/$imagename k8s.gcr.io/$imagename
docker rmi -f $url/$imagename
done
[root@master01 ~]# chmod +x image.sh
[root@master01 ~]# ./image.sh
kubeadm init --pod-network-cidr=10.244.0.0/16
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes