华为云K8S集群搭建
一、初始化ECS后,先更新服务器基础环境
yum update -y
二、基础环境搭建(整个集群都要执行)
#修改服务器名称
hostnamectl set-hostname k8s-01
hostnamectl set-hostname k8s-02
hostnamectl set-hostname k8s-03
#修改hosts文件
vim /etc/hosts
192.168.0.72 k8s-01
192.168.0.217 k8s-02
192.168.0.205 k8s-03
#修改内核参数
sysctl -w net.bridge.bridge-nf-call-iptables=1
#关闭防火墙、SElinux:
systemctl stop firewalld && systemctl disable firewalld
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
#关闭swap空间
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
#重启服务器
reboot
三、Dokcer安装(整个集群都要执行)
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce-18.09.9 -y
systemctl start docker
systemctl enable docker
#启动docker后,可以使用docker info 查看docker版本详情
四、安装kubeadmin组件
#导入阿里云镜像仓库源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-aarch64/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
#安装kubectl
yum install -y kubelet-1.14.2 kubectl-1.14.2 kubeadm-1.14.2 kubernetes-cni-0.7.5
#安装完整后,检查版本
[root@k8s-01 ~]# rpm -qa | grep kubelet
kubelet-1.14.2-0.aarch64
[root@k8s-01 ~]# rpm -qa | grep kubeadm
kubeadm-1.14.2-0.aarch64
[root@k8s-01 ~]# rpm -qa | grep kubectl
kubectl-1.14.2-0.aarch64
[root@k8s-01 ~]# rpm -qa | grep kubernetes-cn
kubernetes-cni-0.7.5-0.aarch64
#设置iptables
echo "net.bridge.bridge-nf-call-iptables=1" > /etc/sysctl.d/k8s.conf
#开机启动kubelet服务
systemctl start kubelet
systemctl enable kubelet
五、下载k8s所需镜像
#查看kubeadmin所需镜像
kubeadm config images list
#上条命令得到镜像及版本后使用docker pull拉取,但由于国外源无法直接获取,可以尝试用其他源pull之后,使用tag打包
docker pull docker.io/mirrorgooglecontainers/kube-apiserver-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/kube-controller-manager-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/kube-scheduler-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/kube-proxy-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/pause-arm64:3.1
docker pull docker.io/mirrorgooglecontainers/etcd-arm64:3.3.10
docker pull docker.io/coredns/coredns:1.3.1
#使用docker images 查看已拉取的镜像
[root@k8s-03 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mirrorgooglecontainers/kube-proxy-arm64 v1.14.2 5227f1c3c8a7 2 years ago 82.7MB
mirrorgooglecontainers/kube-apiserver-arm64 v1.14.2 091f78b1b081 2 years ago 207MB
mirrorgooglecontainers/kube-controller-manager-arm64 v1.14.2 e0fa3d206e49 2 years ago 155MB
mirrorgooglecontainers/kube-scheduler-arm64 v1.14.2 485238b2c4a5 2 years ago 82.2MB
coredns/coredns 1.3.1 7e8edeee9a1e 3 years ago 37.4MB
mirrorgooglecontainers/etcd-arm64 3.3.10 ad99d3ead043 3 years ago 300MB
mirrorgooglecontainers/pause-arm64 3.1 6cf7c80fe444 4 years ago 525kB
六、给镜像打TAG ,打成刚刚kubeadm config images list 所反回的镜像
docker tag mirrorgooglecontainers/kube-apiserver-arm64:v1.14.2 k8s.gcr.io/kube-apiserver:v1.14.2
docker tag mirrorgooglecontainers/kube-controller-manager-arm64:v1.14.2 k8s.gcr.io/kube-controller-manager:v1.14.2
docker tag mirrorgooglecontainers/kube-scheduler-arm64:v1.14.2 k8s.gcr.io/kube-scheduler:v1.14.2
docker tag mirrorgooglecontainers/kube-proxy-arm64:v1.14.2 k8s.gcr.io/kube-proxy:v1.14.2
docker tag mirrorgooglecontainers/pause-arm64:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd-arm64:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
#打完tag之后,清理掉不用的docke镜像,只保留k8s.gcr开头的镜像即可
[root@k8s-01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-apiserver v1.14.2 091f78b1b081 2 years ago 207MB
k8s.gcr.io/kube-controller-manager v1.14.2 e0fa3d206e49 2 years ago 155MB
k8s.gcr.io/kube-scheduler v1.14.2 485238b2c4a5 2 years ago 82.2MB
k8s.gcr.io/kube-proxy v1.14.2 5227f1c3c8a7 2 years ago 82.7MB
k8s.gcr.io/coredns 1.3.1 7e8edeee9a1e 3 years ago 37.4MB
k8s.gcr.io/etcd 3.3.10 ad99d3ead043 3 years ago 300MB
k8s.gcr.io/pause 3.1 6cf7c80fe444 4 years ago 525kB
七、部署
|