blog/kubernetes/mantaince/add_new_node.md

26 lines
568 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# kubeadm添加一个新的节点
首先获取证书的hash值 这个值用于 `--discovery-token-ca-cert-hash`
```bash
HASH=$(openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //')
```
获取token, 这个值用于 `--token`
```bash
kubeadm token list
```
如果没有任何token列出创建一个
```bash
TOKEN=$(kubeadm token create)
```
添加节点到集群
```bash
kubeadm join k8smaster:6443 --token ${TOKEN} --discovery-token-ca-cert-hash sha256:${HASH}
```