-
kubernetes架构图
-
部署环境
- OS:CentOS Linux release 7.6.1810 (Core)
- kernel: 3.10.0-957.21.3.el7.x86_64
- iptables\selinux 关闭
- 1 master 2 node
-
repo环境准备
- Centos_repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- docker_repo
wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- kubernetes_repo
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
- 安装
所有设备均执行如下命令 yum install -y kubelet kubeadm kubectl docker-ce systemctl enable docker kubelet
- 下载所需docker镜像
这里下载v1.15.0版本 docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.15.0 docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.15.0 docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.10.0 docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.15.0 docker pull mirrorgooglecontainers/pause:3.1 docker pull mirrorgooglecontainers/etcd:3.3.10 docker pull coredns/coredns:1.3.1 镜像打标 docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.15.0 k8s.gcr.io/kube-apiserver:v1.15.0 docker tag mirrorgooglecontainers/kube-scheduler:v1.15.0 k8s.gcr.io/kube-scheduler:v1.15.0 docker tag mirrorgooglecontainers/kube-controller-manager:v1.15.0 k8s.gcr.io/kube-controller-manager:v1.15.0 docker tag mirrorgooglecontainers/etcd:v1.15.0 k8s.gcr.io/etcd:v1.15.0 docker tag mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10 docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1 docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1 镜像分发打包 docker save -o k8s-master.tar.gz `docker image ls |grep k8s |awk '{position=$1":"$2;print $1,position}' |awk '{print $2}'` 导入镜像 [root@master ~]# docker load -i k8s-master.tar.gz Loaded image: k8s.gcr.io/etcd:3.3.10 Loaded image: k8s.gcr.io/pause:3.1 Loaded image: k8s.gcr.io/kube-proxy:v1.15.0 Loaded image: k8s.gcr.io/kube-apiserver:v1.15.0 Loaded image: k8s.gcr.io/kube-controller-manager:v1.15.0 Loaded image: k8s.gcr.io/kube-scheduler:v1.15.0 Loaded image: k8s.gcr.io/coredns:1.3.1
- 初始化master
docker 服务器开启 [root@master ~]# systemctl start docker 忽略swap报错 [root@master ~]# vim /etc/sysconfig/kubelet KUBELET_EXTRA_ARGS="--fail-swap-on=false" 安装 kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=Swap #10.244.0.0/16为pod网络 server网络默认为10.96.0.0/12 kubectl 客户端用户配置文件配置 mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config 记录安装后输出,供后面添加work-node使用 kubeadm join 10.193.116.83:6443 --token cmpc1v.bxbssutot9uwn3go \ --discovery-token-ca-cert-hash sha256:a6206427396768bf14a9bb85bf3d726ad5441ccd646a3949ece417b1607a2c2b 安装flannel网络 kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- 添加work-node
work-node节点需要 kube-proxy和flanner即可,打包所需镜像 docker save -o k8s-node.tar.gz quay.io/coreos/flannel:v0.11.0-amd64 \ k8s.gcr.io/pause:3.1 k8s.gcr.io/kube-proxy:v1.15.0 在work-node节点上load镜像 [root@node1 ~]# docker load -i k8s-node.tar.gz 加入master [root@node1 ~]# kubeadm join 10.193.116.83:6443 --token cmpc1v.bxbssutot9uwn3go \ --discovery-token-ca-cert-hash sha256:a6206427396768bf14a9bb85bf3d726ad5441ccd646a3949ece417b1607a2c2b
- Centos_repo
查看集群状态
[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 7h57m v1.15.0
node1 Ready <none> 5h42m v1.15.0
node2 Ready <none> 141m v1.15.0