mirror of
https://gitlab.com/game-loader/hugo.git
synced 2025-04-19 21:42:07 +08:00
devops update
This commit is contained in:
parent
4aa9d1532c
commit
6b9539bd2c
@ -103,6 +103,178 @@ stringData:
|
|||||||
retries: 5
|
retries: 5
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### k8s 主节点安装及启动
|
||||||
|
|
||||||
|
1. 安装docker和containerd
|
||||||
|
|
||||||
|
参照[docker官网ubuntu安装文档](https://docs.docker.com/engine/install/ubuntu/)
|
||||||
|
|
||||||
|
如果使用apt包管理器方法安装,安装后会同时安装docker和containerd。无需再额外安装containerd运行时。
|
||||||
|
|
||||||
|
2. 配置cgroup驱动
|
||||||
|
|
||||||
|
cgroup 驱动是用来管理和组织 Linux 系统中的 cgroups(控制组)的接口。ubuntu中默认使用systemd作为初始化系统,而当当某个 Linux 系统发行版使用 systemd 作为其初始化系统时,初始化进程会生成并使用一个 root 控制组(cgroup),并充当 cgroup 管理器。则要将systemd配置为容器运行时的cgroup系统。
|
||||||
|
|
||||||
|
- 生成默认配置文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo containerd config default | sudo tee /etc/containerd/config.toml
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- 编辑配置文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo vim /etc/containerd/config.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
- 找到runc部分并修改(通常在中间位置)
|
||||||
|
|
||||||
|
```toml
|
||||||
|
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
|
||||||
|
runtime_type = "io.containerd.runc.v2"
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
||||||
|
SystemdCgroup = true
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- 重启containerd服务并检查
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl restart containerd
|
||||||
|
|
||||||
|
sudo crictl info | grep -i cgroup
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
此时应该能看到`SystemdCgroup: true`这样的输出
|
||||||
|
|
||||||
|
3. 临时关闭swap
|
||||||
|
|
||||||
|
Kubernetes 默认不支持启用 swap 的节点,因此在启用swap的节点上kubelet无法正常启动,可以临时关闭swap后继续集群的初始化操作。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo swapoff -a
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 配置容器镜像
|
||||||
|
|
||||||
|
如果不配置容器镜像会导致不能拉取成功从而无法正常启动控制节点,离线情况下要将镜像提前下载好,可以使用如下方式
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看需要的镜像
|
||||||
|
kubeadm config images list
|
||||||
|
|
||||||
|
# 拉取镜像
|
||||||
|
kubeadm config images pull
|
||||||
|
|
||||||
|
# 将镜像保存为tar文件
|
||||||
|
docker save -o k8s-images.tar $(kubeadm config images list)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
在需要的机器上加载镜像
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在离线环境中加载镜像
|
||||||
|
docker load -i k8s-images.tar
|
||||||
|
```
|
||||||
|
|
||||||
|
而在可以连接网络的情况下,可以设置containerd的镜像地址,修改containerd的配置文件config.toml
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# 其他配置...
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".registry]
|
||||||
|
config_path = ""
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
|
||||||
|
endpoint = ["https://hub.rat.dev"]
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."k8s.gcr.io"]
|
||||||
|
endpoint = ["https://registry.aliyuncs.com/google_containers"]
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
5. 使用kubeadm 初始化集群
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 初始化集群控制台 Control plane,保险起见此处也加上镜像地址
|
||||||
|
# 失败了可以用 kubeadm reset 重置
|
||||||
|
|
||||||
|
# 此命令某些情况下可行
|
||||||
|
kubeadm init --image-repository=registry.aliyuncs.com/google_containers
|
||||||
|
|
||||||
|
# 在使用flannel的情况下应该添加下面这条命令中的参数
|
||||||
|
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
失败需要将集群重置,可参考[移除节点](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#remove-the-node)。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubeadm reset
|
||||||
|
|
||||||
|
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
|
||||||
|
|
||||||
|
ipvsadm -C
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
注意此处限于刚启动集群中没有其他工作负载的情况,有工作负载则要先清空节点负载,再重置。
|
||||||
|
|
||||||
|
6. 完成初始化工作并安装pod网络附加组件(
|
||||||
|
|
||||||
|
根据控制台给出的提示
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
先设定kubeconfig,kubeconfig可以告诉kubectl在哪里找到集群的配置信息,从而让kubectl能够成功控制集群,其中包含访问k8s集群需要的认证信息。
|
||||||
|
|
||||||
|
非root用户使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p $HOME/.kube
|
||||||
|
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
|
||||||
|
sudo chown $(id -u):$(id -g) $HOME/.kube/config
|
||||||
|
```
|
||||||
|
|
||||||
|
root用户使用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export KUBECONFIG=/etc/kubernetes/admin.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
安装pod网络附加组件,[可用的组件列表](https://kubernetes.io/zh-cn/docs/concepts/cluster-administration/addons/#networking-and-network-policy),这里安装比较常用的flannel。安装网络组件后pod网络之间才能互通,coreDNS才会启动。
|
||||||
|
|
||||||
|
可使用kubectl或者helm安装,这里使用kubectl安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
注意github可能不能访问,可以直接将这个yml下载下来并保存到主机上,随后将apply的文件替换为本地文件即可,注意flannel拉取的仓库是ghcr.io即github的包管理地址,因此也要将这个地址设置镜像地址,可以使用
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."ghcr.io"]
|
||||||
|
endpoint = ["https://docker.imgdb.de/ghcr.io"]
|
||||||
|
```
|
||||||
|
|
||||||
|
此处使用该方法启动flannel失败,显示不能获取控制平面节点的CIDR,参阅[初始化控制平面节点](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#initializing-your-control-plane-node)可知,使用一些第三方网络插件时可能需要设置--pod-network-cidr,因此要重置集群并重新init并加入--pod-network-cidr参数,如下
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16
|
||||||
|
```
|
||||||
|
|
||||||
|
再重新启动flannel,至此集群初始化全部完成,已经可以运行负载
|
||||||
|
|
||||||
|
如果想要在该控制平面机器上调度其他pod,则要通过下面的命令将从任何拥有 node-role.kubernetes.io/control-plane:NoSchedule 污点的节点(包括控制平面节点)上移除该污点。 这意味着调度程序将能够在任何地方调度 Pod。可参考[控制平面节点隔离](https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#control-plane-node-isolation)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl taint nodes --all node-role.kubernetes.io/control-plane
|
||||||
|
```
|
||||||
|
|
||||||
## 修复不同节点使用内网ip不互通的问题(异地组网)
|
## 修复不同节点使用内网ip不互通的问题(异地组网)
|
||||||
|
|
||||||
### 修改master节点flannel配置文件
|
### 修改master节点flannel配置文件
|
||||||
|
Loading…
Reference in New Issue
Block a user