Docker安装
信任Docker的GPG公钥:
curl -fsSL https://repo.huaweicloud.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -`
添加软件仓库:
sudo add-apt-repository "deb [arch=amd64] https://repo.huaweicloud.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
更新索引文件并安装
sudo apt-get update
sudo apt-get install docker-ce
Docker配置
添加国内镜像仓库
root@ubuntu:# cat /etc/docker/daemon.json
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://1nj0zren.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
]
}
保存后执行
sudo systemctl daemon-reload
sudo systemctl restart docker
安装指定版本(可选)
由于Kubernetes在1.20版本后,官方不再对Docker作为容器运行时提供官方支持,因此如果仍然希望使用docker需要安装指定版本的Kubernetes。安装指定版本docker操作如下,Kubernetes同理。
sudo apt-cache policy docker-ce
sudo apt-get install docker-ce=5:20.10.7~3-0~ubuntu-xenial
我的软件版本
docker 19.03.13
Kubernetes v1.18.0
Kubernetes安装
关闭防火墙及虚拟内存、selinux
ufw disable
swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab
setenforce 0
修改/etc/apt/sources.list.d/kubernetes.list文件
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb https://repo.huaweicloud.com/kubernetes/apt/ kubernetes-xenial main
EOF
添加kubernetes的key
curl -s https://repo.huaweicloud.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
更新索引文件并安装kubernetes
sudo apt update
sudo apt install -y kubeadm kubelet kubectl
初始化Master
kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.18.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.45.227
执行该命令会自动下载需要的镜像进行初始化,由于某些原因Google访问不了,因此指定了国内的仓库。如果仍然不行,可以考虑使用手动通过docker pull的方式拉取镜像。
手动拉取镜像
首先列出需要的镜像
kubeadm config images list --kubernetes-version v1.18.0
依据列出的镜像列表手动拉取
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.18.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.18.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.18.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.18.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7
给拉取下来的镜像修改tag,版本号需要前后一致,需要根据自己所需进行修改
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.18.0 k8s.gcr.io/kube-apiserver:v1.18.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.18.0 k8s.gcr.io/kube-controller-manager:v1.18.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.18.0 k8s.gcr.io/kube-scheduler:v1.18.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.18.0 k8s.gcr.io/kube-proxy:v1.18.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7 k8s.gcr.io/coredns:1.6.7
依据给出的信息创建配置以及添加新的node,记得apiserver替换成自己的ip地址,至于cidr子网可以考虑不更改,因为后续需要安装flannel,而flannel默认网段是10.244.0.0/16。
kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.45.227
Your Kubernetes control-plane has initialized successfully!
#首先执行以下这段
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
#之后在别的节点主机上执行以下命令,将别的Node挂到master节点下
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.45.227:6443 --token hbbn5i.u6fqjr0phforyr2q \
--discovery-token-ca-cert-hash sha256:e3f40cb90a3d791deaf6b6606ec500cffc8b48d0351b085cd0d4f74a6ce0e794
安装flannel
如果无法访问可以直接将yaml文件下载到本机再apply
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
最后确认集群所有节点的状态
root@ubuntu:# kubectl get nodes
NAME STATUS ROLES AGE VERSION
adolph-server Ready <none> 7d20h v1.18.0
ubuntu Ready master 7d20h v1.18.0
ubuntu-b Ready <none> 7d20h v1.18.0
标签:v1.18,aliyuncs,cn,Kubernetes,部署,registry,Ubuntu,docker,com
From: https://www.cnblogs.com/Modest-Hamilton/p/17553993.html