Kubeadm初始化Kubernetes集群
程序员文章站
2022-07-13 22:19:22
...
1.环境
- matser,etcd: 192.168.33.30
- node1: 192.168.33.40
- node2: 192.168.33.50
前提
- 1、基于主机名通信:/etc/hosts
- 2、时间同步
- 3、关闭firewall和iptables.service
- 4、OS:CentOS 7.6.1810
安装配置步骤:
- 1、etcd cluster,仅master节点;
- 2、flannel,集群的所有节点;
- 3、配置K8s的master:仅master节点;
- kubenetes-master
- 启动的服务:kube-apiserver,kube-scheduler,kube-controller-manager
- 4、配置k8s的各node节点:Kubernetes-node
- 先设定启动docker服务;启动k8s的服务:kube-proxy,kubelet
kubeadm
- 1、master,node:安装kubelet,kubeamd,docker
- 2、master:kubeadm init
- 3、nodes:kubeadm join
master部署
-
安装dokcer-ce
-
配置阿里云的Kubernetes源
[[email protected] yum.repos.d]# vim kubernetes.repo [kubernetes] name=kubernetes Repo baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg enabled=1
-
把Kubernetes源分别复制到node1和node2
[[email protected] yum.repos.d]# scp kubernetes.repo node1:/etc/yum.repos.d/ [[email protected] yum.repos.d]# scp kubernetes.repo node2:/etc/yum.repos.d/
-
yum安装kubeadm、kubelet、kubectl
[[email protected] yum.repos.d]# yum install kubeadm kubelet kubectl
注:出现d87e7e3e61cc561f18376d2caa53207ba96b932ca2011be9e8e370bdc281d859-kubeadm-1.15.3-0.x86_64.rpm 的公钥尚未安装解决办法
[[email protected] yum.repos.d]# vim kubernetes.repo gpgcheck=0 [[email protected] yum.repos.d]# cd [[email protected] ~]# wget https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg [[email protected] ~]# rpm --import yum-key.gpg [[email protected] ~]# yum install kubeadm kubelet kubectl
-
设置docker的环境变量
[[email protected] ~]# vim /usr/lib/systemd/system/docker.service [Service] ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT [[email protected] ~]# systemctl daemon-reload [[email protected] ~]# systemctl restart docker.service [[email protected] ~]# docker info
-
查看kubelet的目录
[[email protected] ~]# rpm -ql kubelet
/etc/kubernetes/manifests
/etc/sysconfig/kubelet
/usr/bin/kubelet
/usr/lib/systemd/system/kubelet.service
- 设置docker、kubelet开机自启
[[email protected] ~]# systemctl enable docker.service [[email protected] ~]# systemctl enable kubelet.service
- kubeamd初始化
[[email protected] ~]# docker pull mirrorgooglecontainers/kube-apiserver:v1.15.0
[[email protected] ~]# docker pull mirrorgooglecontainers/kube-controller-manager:v1.15.0
[[email protected] ~]# docker pull mirrorgooglecontainers/kube-scheduler:v1.15.0
[[email protected] ~]# docker pull mirrorgooglecontainers/kube-proxy:v1.15.0
[[email protected] ~]# docker pull mirrorgooglecontainers/pause:3.1
[[email protected] ~]# docker pull mirrorgooglecontainers/etcd:3.3.10
[[email protected] ~]# docker pull coredns/coredns:1.3.1
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/kube-apiserver:v1.15.0 k8s.gcr.io/kube-apiserver:v1.15.0
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/kube-controller-manager:v1.15.0 k8s.gcr.io/kube-controller-manager:v1.15.0
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/kube-scheduler:v1.15.0 k8s.gcr.io/kube-scheduler:v1.15.0
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/kube-proxy:v1.15.0 k8s.gcr.io/kube-proxy:v1.15.0
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
[[email protected] ~]# docker tag docker.io/coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
[[email protected] ~]# vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
[[email protected] ~]# kubeadm init --kubernetes-version=v1.11.1 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
- 把yum-key.gpg分别复制给node1和node2
[[email protected] ~]# scp yum-key.gpg node1:/root
[[email protected] ~]# scp yum-key.gpg node2:/root
- 创建kebe配置文件,认证证书
[[email protected] ~]# mkdir -p $HOME/.kube
[[email protected] ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
11.手动部署flannel,且要指定namespace
[[email protected] ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 44h v1.15.3
[[email protected] ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-5c98db65d4-55zlf 1/1 Running 0 44h
coredns-5c98db65d4-qsb7s 1/1 Running 0 44h
etcd-master 1/1 Running 0 44h
kube-apiserver-master 1/1 Running 0 44h
kube-controller-manager-master 1/1 Running 1 44h
kube-flannel-ds-amd64-xpflj 1/1 Running 0 5m58s
kube-proxy-6x6sx 1/1 Running 0 44h
kube-scheduler-master 1/1 Running 1 44h
node1部署
1.yum安装docker、kubeadm、kubelet
[[email protected] ~]# rpm --import yum-key.gpg
[[email protected] ~]# yum install kubelet kubeadm
2.在master中把相关的配置文件复制到node1和node2
[[email protected] ~]# scp /usr/lib/systemd/system/docker.service node1:/usr/lib/systemd/system/docker.service
[[email protected] ~]# scp /usr/lib/systemd/system/docker.service node2:/usr/lib/systemd/system/docker.service
[[email protected] ~]# scp /etc/sysconfig/kubelet node1:/etc/sysconfig/
[[email protected] ~]# scp /etc/sysconfig/kubelet node2:/etc/sysconfig/
3.重启docker,并把kubelet加入开机自启
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl restart docker.service
[[email protected] ~]# systemctl enable kubelet.service
4.在node1上下载组件镜像
[[email protected] ~]# docker pull mirrorgooglecontainers/kube-proxy:v1.15.0
[[email protected] ~]# docker pull mirrorgooglecontainers/pause:3.1
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/kube-proxy:v1.15.0 k8s.gcr.io/kube-proxy-amd64:v1.15.0
[[email protected] ~]# docker tag docker.io/mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
[[email protected] ~]# docker rmi mirrorgooglecontainers/kube-proxy:v1.15.0
[[email protected] ~]# docker rmi mirrorgooglecontainers/pause:3.1
5.把node1节点加入集群
[[email protected] ~]# kubeadm token create --ttl 0 --print-join-command
kubeadm join 192.168.33.30:6443 --token 9n0jkf.xu5rdhgz8db2aurk --discovery-token-ca-cert-hash sha256:75f6da989069173c6092c3a127912bee2cc30f16eb3b2c0d442f0081bc5751dc
[[email protected] ~]# kubeadm join 192.168.33.30:6443 --token q8mkp7.61eo6ayjhanap8uv --discovery-token-ca-cert-hash sha256:75f6da989069173c6092c3a127912bee2cc30f16eb3b2c0d442f0081bc5751dc --ignore-preflight-errors=Swap
6.在master上查看node1是否加入
[[email protected] ~]# kubectl get pods -n kube-system -o wide
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 47h v1.15.3
node1 Ready <none> 99s v1.15.3
node2加入集群跟node1一样
上一篇: Etcd集群环境搭建
下一篇: Unity事件
推荐阅读
-
使用Kubeadm在CentOS7.2上部署Kubernetes集群的方法
-
附012.Kubeadm部署高可用Kubernetes
-
在 Kubernetes 集群快速部署 KubeSphere 容器平台
-
使用KubeAdm部署Kubernetes集群——如何访问google代码仓库及Yum源
-
【DevOps】在CentOS中安装Rancher2,并配置kubernetes集群
-
kubernetes系列03—kubeadm安装部署K8S集群
-
云主机搭建Kubernetes 1.10集群
-
附003.Kubeadm部署Kubernetes
-
kubeadm创建k8s集群一直失败排查
-
kubeadm搭建的k8s集群升级