CodeSnippet.Cn
代码片段
Csharp
架构设计
.NetCore
西班牙语
kubernetes
MySql
Redis
Algorithm
Ubuntu
Linux
Other
.NetMvc
VisualStudio
Git
pm
Python
WPF
java
Plug-In
分布式
CSS
微服务架构
JavaScript
DataStructure
Shared
K8S(5)——使用 kubeadm 配置 slave 节点 Ubuntu
0
kubernetes
小笨蛋
发布于:2021年09月20日
更新于:2021年10月10日
185
#custom-toc-container
> Ubuntu18.4 ### 概述 将 slave 节点加入到集群中很简单,只需要在 slave 服务器上安装 `kubeadm`,`kubectl`,`kubelet` 三个工具,然后使用 `kubeadm join` 命令加入即可。准备工作如下: - 修改主机名 `hostnamectl set-hostname kubernetes-slave1` [查看详细-修改主机名](https://www.codesnippet.cn/home/list/85#%E4%BF%AE%E6%94%B9%E4%B8%BB%E6%9C%BA%E5%90%8D "查看详细-修改主机名") - 修改 cloud.cfg [查看详细-修改 cloud.cfg](https://www.codesnippet.cn/home/list/85#%E4%BF%AE%E6%94%B9%E4%B8%BB%E6%9C%BA%E5%90%8D "查看详细-修改 cloud.cfg") - 配置软件源 [查看详细-配置软件源](https://www.codesnippet.cn/home/list/86#%E9%85%8D%E7%BD%AE%E8%BD%AF%E4%BB%B6%E6%BA%90 "查看详细-配置软件源") - 安装三个工具 由于之前章节已经说明了操作步骤,此处不再赘述。 ### 将 slave 加入到集群 ================================ **错误解决方案** `The HTTP call equal to ‘curl -sSL http://localhost:10255/healthz‘ failed with error: Get http://localhost:10255/healthz: dial tcp 127.0.0.1: 10255: getsockopt: connection refused.` `vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf` 把主节点的配置拷贝到子节点相应的文件中 保存后运行 `systemctl daemon-reload` 与 `systemctl restart kubelet` -------------------------------- 运行`kubectl get nodes`命令如出现 `The connection to the server localhot:8080 was refused - did you specify the right host or port?` 在主节点把admin.conf文件分发到node节点,然后执行 `mkdir -p $HOME/.kube` `cp -i /etc/kubernetes/admin.conf $HOME/.kube/config` 即可 ================================ `kubeadm join 192.168.239.128:6443 --token abcdef.0123456789abcdef \ --discovery-token-ca-cert-hash sha256:be599224ebb58c94deb7113924d755b34358ce94ff5ac6cd991c411b1d2e34c0` 上面这句命令的要通过查询 `kubeadm-init.log` 文件来得到 ![](/uploads/images/20210920/123652-fba394860cea4cc2a22b9a7b4f895cca.png) ![](/uploads/images/20210920/123828-c7f37b7f2c3b40bba5b664428063b220.png) ```shell # 安装成功将看到如下信息 [preflight] Running pre-flight checks [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/ [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml' [kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.14" ConfigMap in the kube-system namespace [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Activating the kubelet service [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details. Run 'kubectl get nodes' on the control-plane to see this node join the cluster. ``` 说明: - token - 可以通过安装 master 时的日志查看 token 信息 - 可以通过 `kubeadm token list` 命令打印出 token 信息 - 如果 token 过期,可以使用 `kubeadm token create` 命令创建新的 token - discovery-token-ca-cert-hash - 可以通过安装 master 时的日志查看 sha256 信息 - 可以通过 `openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'` 命令查看 sha256 信息 ### 验证是否成功 回到 master 服务器 ```shell kubectl get nodes # 可以看到 slave 成功加入 master NAME STATUS ROLES AGE VERSION kubernetes-master NotReady master 9h v1.14.1 kubernetes-slave1 NotReady
22s v1.14.1 ``` > 如果 slave 节点加入 master 时配置有问题可以在 slave 节点上使用 `kubeadm reset` 重置配置再使用 `kubeadm join` 命令重新加入即可。希望在 master 节点删除 node ,可以使用 `kubeadm delete nodes
` 删除。 ### 查看 pod 状态 ```shell kubectl get pod -n kube-system -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES coredns-8686dcc4fd-gwrmb 0/1 Pending 0 9h
coredns-8686dcc4fd-j6gfk 0/1 Pending 0 9h
etcd-kubernetes-master 1/1 Running 1 9h 192.168.141.130 kubernetes-master
kube-apiserver-kubernetes-master 1/1 Running 1 9h 192.168.141.130 kubernetes-master
kube-controller-manager-kubernetes-master 1/1 Running 1 9h 192.168.141.130 kubernetes-master
kube-proxy-496dr 1/1 Running 0 17m 192.168.141.131 kubernetes-slave1
kube-proxy-rsnb6 1/1 Running 1 9h 192.168.141.130 kubernetes-master
kube-scheduler-kubernetes-master 1/1 Running 1 9h 192.168.141.130 kubernetes-master
``` 由此可以看出 coredns 尚未运行,此时我们还需要安装网络插件。
这里⇓感觉得写点什么,要不显得有点空,但还没想好写什么...
返回顶部
About
京ICP备13038605号
© 代码片段 2024