Centos7部署Kubernetes最新版1.12.3
安裝docker-ce
yum-config-manager --add-repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce
如果不行改成下面這樣
[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-edge] name=Docker CE Edge - $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/$basearch/edge enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-edge-debuginfo] name=Docker CE Edge - Debuginfo $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/debug-$basearch/edge enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-edge-source] name=Docker CE Edge - Sources baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/source/edge enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/7/source/nightly enabled=0 gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/gpg
有公網IP的ECS
echo ‘[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‘>/etc/yum.repos.d/kubernetes.repo
VPC網絡的ECS
echo ‘[kubernetes] name=Kubernetes baseurl=http://mirrors.cloud.aliyuncs.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.cloud.aliyuncs.com/kubernetes/yum/doc/rpm-package-key.gpg‘>/etc/yum.repos.d/kubernetes.repo
所有節點安裝
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet
Master節點
kubeadm init --kubernetes-version=1.12.3 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=master節點的IP
等了半天報錯,原因是下載鏡像失敗
報錯是因為我們是民主國家,你懂的,提供以下兩種方案
1 手動方案
先修改默認存儲位置和鏡像加速
echo ‘{"registry-mirrors": ["https://registry.docker-cn.com"],"graph": "/data/docker"}‘ > /etc/docker/daemon.json
systemctl enable docker
systemctl start docker
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:v1.12.3
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.12.3
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:v1.12.3
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:v1.12.3
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:3.2.24
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
[root@k8s-m ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.2
[root@k8s-m ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64 v1.12.1 61afff57f010 12 days ago 96.6MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64 v1.12.1 dcb029b5e3ad 12 days ago 194MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64 v1.12.1 aa2dd57c7329 12 days ago 164MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64 v1.12.1 d773ad20fd80 12 days ago 58.3MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64 3.2.24 3cab8e1b9802 3 weeks ago 220MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.2.2 367cdc8433a4 7 weeks ago 39.2MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 10 months ago 742kB
重新TAG
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:v1.12.3 k8s.gcr.io/kube-scheduler:v1.12.3
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.12.3 k8s.gcr.io/kube-controller-manager:v1.12.3
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:v1.12.3 k8s.gcr.io/kube-apiserver:v1.12.3
[root@k8s-m ~]# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:v1.12.3 k8s.gcr.io/kube-proxy:v1.12.3
2 自動方案
所有節點
mkdir -p /data/operations/script/
以上鏡像操作部分可以批量執行的shell腳本(需要公網IP)
echo ‘
#!/bin/bash
systemctl enable docker
systemctl start docker
echo ‘{"registry-mirrors": ["https://registry.docker-cn.com"],"graph": "/data/docker"}‘ > /etc/docker/daemon.json
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:v1.12.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.12.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:v1.12.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:v1.12.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:3.2.24
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.3 k8s.gcr.io/coredns:1.2.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.4 k8s.gcr.io/coredns:1.2.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:v1.12.3 k8s.gcr.io/kube-scheduler:v1.12.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.12.3 k8s.gcr.io/kube-controller-manager:v1.12.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:v1.12.3 k8s.gcr.io/kube-apiserver:v1.12.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:v1.12.3 k8s.gcr.io/kube-proxy:v1.12.3‘ > /data/operations/script/images.sh
chmod +x /data/operations/script/images.sh
sh /data/operations/script/images.sh
kubeadm init --kubernetes-version=1.12.3 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.0.170
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
kubeadm join 172.16.0.51:6443 --token j0u8rp.wknfkxa8ynw89lq8 --discovery-token-ca-cert-hash sha256:e946decc81a2dc06268425e5312a2c9eced90c79683e5e5e05b93b5cf43df054
這裏生成的初始token可能無法使用,如果無法使用執行以下命令新生成一個
kubeadm token create --print-join-command
二、所有節點通用操作
[root@k8s-m ~]# echo ‘[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‘>/etc/yum.repos.d/kubernetes.repo
[root@k8s-m ~]# yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
已安裝:
kubeadm.x86_64 0:1.12.1-0 kubectl.x86_64 0:1.12.1-0 kubelet.x86_64 0:1.12.1-0
作為依賴被安裝:
cri-tools.x86_64 0:1.12.0-0 kubernetes-cni.x86_64 0:0.6.0-0 socat.x86_64 0:1.7.3.2-2.el7
[root@k8s-m ~]# systemctl enable kubelet && systemctl start kubelet
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /etc/systemd/system/kubelet.service.
kubeadm join 10.0.0.170:6443 --token 6s89xu.1x06dy6c1vvyl22n --discovery-token-ca-cert-hash sha256:868b352cb5865ae4dc0c5a0394e94e92cfbb8ba3a8615590aab4292ce1cef17e
TIPS
如果缺少部分鏡像請到阿裏雲的容器鏡像服務中搜索,下載後重新TAG
Centos7部署Kubernetes最新版1.12.3