Kubernetes in Docker,单机运行 Kubernetes 群集的最佳方案.
没有足够的机器运行 Kubernetes 测试环境;个人电脑配置不高的话,运行多个节点的虚拟化有点力不从心;国内公有云主机一般不支持嵌套虚拟化;Kind是Google 官方的一个工具,可能是在单机运行 Kubernetes 群集的最佳方案.
kind 是 Kubernetes in Docker 的简写,是一个使用 Docker 容器作为 Nodes,在本地创建和运行 Kubernetes 群集的工具。适用于在本机创建 Kubernetes 群集环境进行开发和测试。
kind官网地址:https://kind.sigs.k8s.io/docs/user/quick-start/
官方架构图:
由于kind使用的是docker in docker的原理,kind 使用 kubeadm 创建和启动群集节点;kind 使用 containerd 作为容器运行时.
基于Ubuntu22.04
# step 1: 安装GPG证书sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -# Step 2: 写入软件源信息sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"# Step 3: 更新并安装Docker-CEsudo apt -y updatesudo apt -y install docker-ce这里建议大家安装最新版本即可
sudo curl -sL https://github.com/kubernetes-sigs/kind/releases/download/v0.14.0/kind-linux-amd64 -o /usr/local/bin/kindsudo chmod +x /usr/local/bin/kindsudo kind version这里我通过apt源来进行安装,大家也可以自行去GitHub上下载最新版本的kubectl二进制文件。
sudo cat </etc/apt/sources.list.d/kubernetes.listdeb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial mainEOFsudo apt updatesudo apt install kubectl #这里默认创建的集群名称为kindsudo kind create cluster --wait 10m #也可以指定集群名称sudo kind create cluster --name my-cluster#由于这里我后安装了kubectl,导致没有kubeconfig配置,使用如下命令导出kubeconfigsudo kind export kubeconfig------------------------------iqimei@iqimei-vm:~/src$ sudo kubectl get pod -n kube-systemNAME READY STATUS RESTARTS AGEcoredns-6d4b75cb6d-5mhwd 1/1 Running 0 12mcoredns-6d4b75cb6d-5xwb4 1/1 Running 0 12metcd-kind-control-plane 1/1 Running 0 13mkindnet-55pxh 1/1 Running 0 12mkube-apiserver-kind-control-plane 1/1 Running 0 13mkube-controller-manager-kind-control-plane 1/1 Running 0 13mkube-proxy-bt4xt 1/1 Running 0 12mkube-scheduler-kind-control-plane 1/1 Running 0 13miqimei@iqimei-vm:~/src$ sudo kubectl get nodeNAME STATUS ROLES AGE VERSIONkind-control-plane Ready control-plane 53m v1.24.0#删除集群sudo kind delete cluster --name kind#多节点集群的配置文件如下:iqimei@iqimei-vm:~/src$ cat kind-3nodes.yaml kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4name: app-1-clusternodes: - role: control-plane extraMounts: - hostPath: /etc/hosts containerPath: /etc/hosts readOnly: true selinuxRelabel: false propagation: HostToContainer - role: worker extraMounts: - hostPath: /etc/hosts containerPath: /etc/hosts readOnly: true selinuxRelabel: false propagation: HostToContainer - role: worker extraMounts: - hostPath: /etc/hosts containerPath: /etc/hosts readOnly: true selinuxRelabel: false propagation: HostToContainer --- #创建集群kind create cluster --config kind-example-config.yaml#获取集群信息sudo kubectl cluster-info --context kind-app-1-cluster#集群配置kubeconfig默认存放再/root/.kube/config当中| 留言与评论(共有 0 条评论) “” |