启动一个虚拟机,centos7.9
| 节点名称 | 节点地址 |
|---|---|
| k8s-single | 10.0.37.147 |
| 我是基于kubespray的官方地址,通过docker来进行安装的,具体请看这个地址 | |
| 首先需要准备安装的inventory.ini,内容如下 |
~ via ☕ v1.8.0 ❯ cat inventory/sample/inventory.ini
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
k8s-single ansible_host=10.0.37.147 ip=10.0.37.147 etcd_member_name=etcd1
# ## configure a bastion host if your nodes are not directly reachable
# [bastion]
# bastion ansible_host=x.x.x.x ansible_user=some_user
[kube_control_plane]
k8s-single
[etcd]
k8s-single
[kube_node]
k8s-single
[calico_rr]
[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr
另外需要配置免密,添加安装主机的秘钥到k8s-single上
docker pull quay.io/kubespray/kubespray:v2.18.1
docker run --rm -it --mount type=bind,source="$(pwd)"/inventory/sample,dst=/inventory \
--mount type=bind,source="${HOME}"/.ssh/id_rsa,dst=/root/.ssh/id_rsa \
quay.io/kubespray/kubespray:v2.18.1 bash
# Inside the container you may now run the kubespray playbooks:
# 添加id_rsa.pub的文件到部署的节点上
ansible-playbook -i /inventory/inventory.ini --private-key /root/.ssh/id_rsa cluster.yml
出现如下日志
报错,下载超时,此时需要考虑下载问题了 sed -i "s|^kubelet_download_url.|#&\nkubelet_download_url: 'http://10.0.37.147:60000/kubelet'|g" main.yml sed -i "s|^kubectl_download_url.*|#&\nkubectl_download_url: 'http://10.0.37.147:60000/kubectl'|g" main.yml sed -i "s|^kubeadm_download_url.|#&\nkubeadm_download_url: 'http://10.0.37.147:60000/kubeadm'|g" main.yml sed -i "s|^etcd_download_url.*|#&\netcd_download_url: 'http://10.0.37.147:60000/etcd-v3.5.3-linux-amd64.tar.gz'|g" main.yml sed -i "s|^cni_download_url.|#&\ncni_download_url: 'http://10.0.37.147:60000/cni-plugins-linux-amd64-v1.0.1.tgz'|g" main.yml sed -i "s|^calicoctl_download_url.*|#&\ncalicoctl_download_url: 'http://10.0.37.147:60000/calicoctl-linux-amd64'|g" main.yml sed -i "s|^crictl_download_url.|#&\ncrictl_download_url: 'http://10.0.37.147:60000/crictl-v1.23.0-linux-amd64.tar.gz'|g" main.yml sed -i "s|^runc_download_url.*|#&\nrunc_download_url: 'http://10.0.37.147:60000/runc.amd64'|g" main.yml sed -i "s|^nerdctl_download_url.*|#&\nnerdctl_download_url: 'http://10.0.37.147:60000/nerdctl-0.19.0-linux-amd64.tar.gz'|g" main.yml sed -i "s|^containerd_download_url.*|#&\ncontainerd_download_url: 'http://10.0.37.147:60000/containerd-1.6.4-linux-amd64.tar.gz'|g" main.yml 再进行安装试试 通过skopem同步镜像到自己的私服 安装registry私服
mkdir /docker/registry -p
docker run -itd -v /docker/registry/:/docker/registry -p 5000:5000 --restart=always --name registry registry:latest
需要同步镜像到registry,需要开启代理同步镜像到hdfs docker中配置daemon.json { "insecure-registries" : ["0.0.0.0/0","10.0.37.152:5000"] }
for image in $(cat temp/images.list); do skopeo copy docker://${image} docker://10.0.37.153:5000/${image#*/} --insecure-policy --dest-tls-verify=false; done
接下来,修改main文件中镜像
第三步修改check_sum,注销掉
接下来安装命令
sudo ansible-playbook -i inventory/mycluster/inventory.ini --private-key /root/.ssh/id_rsa cluster.yml -b -v
,接下来等待安装结果
安装完后,假如kubectl get nodes 变成notready,重启一下服务器即可。