From dda2c223d75cece1e25efd339b215a5dcd04fda1 Mon Sep 17 00:00:00 2001 From: abearixong Date: Thu, 25 Dec 2025 00:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0k8s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- k8s/copy.sh | 2 +- k8s/kevisual.cn/config/master-token.md | 2 +- k8s/readme.md | 11 +++++ k8s/xiongxiao.me/config/env.md | 3 ++ k8s/xiongxiao.me/config/master-token.md | 30 +++++++++++- k8s/xiongxiao.me/config/registry.md | 6 +-- k8s/xiongxiao.me/docs/00-master.md | 4 +- k8s/xiongxiao.me/test/hello/hello.yaml | 62 +++++++++++++++++++++++++ 8 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 k8s/readme.md create mode 100644 k8s/xiongxiao.me/config/env.md create mode 100644 k8s/xiongxiao.me/test/hello/hello.yaml diff --git a/k8s/copy.sh b/k8s/copy.sh index c7947a9..d19b7a6 100644 --- a/k8s/copy.sh +++ b/k8s/copy.sh @@ -1,3 +1,3 @@ -mkdir ~/.kube +# mkdir ~/.kube cp ./config ~/.kube/config \ No newline at end of file diff --git a/k8s/kevisual.cn/config/master-token.md b/k8s/kevisual.cn/config/master-token.md index d595357..8049b0d 100644 --- a/k8s/kevisual.cn/config/master-token.md +++ b/k8s/kevisual.cn/config/master-token.md @@ -4,7 +4,7 @@ K109668b353a17ff6ea9d68535255f880cf583c5c83c357d181ac5f963505033af4::server:f95b ```sh -curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://kevisual.cn:6443 K3S_TOKEN=K109668b353a17ff6ea9d68535255f880cf583c5c83c357d181ac5f963505033af4::server:f95b219abcfe507760f04ff88be52ccd sh - +curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://kevisual.cn:6443 K3S_TOKEN=K109668b353a17ff6ea9d68535255f880cf583c5c83c357d181ac5f963505033af4::server:f95b219abcfe507760f04ff88be52ccd sh - --pause-image=docker.m.daocloud.io/rancher/mirrored-pause:3.9 ``` 会输出类似 diff --git a/k8s/readme.md b/k8s/readme.md new file mode 100644 index 0000000..047c8bb --- /dev/null +++ b/k8s/readme.md @@ -0,0 +1,11 @@ +# 设置默认 context +```sh +kubectl config use-context + + +kubectl config use-context dev-context +``` + +# 查看节点信息 +```sh +kubectl get nodes -o wide \ No newline at end of file diff --git a/k8s/xiongxiao.me/config/env.md b/k8s/xiongxiao.me/config/env.md new file mode 100644 index 0000000..8a349c6 --- /dev/null +++ b/k8s/xiongxiao.me/config/env.md @@ -0,0 +1,3 @@ +```sh +cat /etc/systemd/system/k3s.service.env +``` \ No newline at end of file diff --git a/k8s/xiongxiao.me/config/master-token.md b/k8s/xiongxiao.me/config/master-token.md index 18ef82a..5abc3e4 100644 --- a/k8s/xiongxiao.me/config/master-token.md +++ b/k8s/xiongxiao.me/config/master-token.md @@ -24,4 +24,32 @@ kubectl label nodes vm-32-6-ubuntu machine- --overwrite kubectl label nodes on machine=on --overwrite ### light -kubectl label nodes light machine=light --overwrite \ No newline at end of file +kubectl label nodes light machine=light --overwrite + + +## 关于非内网需要设置实际ip地址 + +```sh +# aliyun, ip: 121.199.37.154 +curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_NODE_IP=121.199.37.154 K3S_NODE_EXTERNAL_IP=121.199.37.154 K3S_URL=https://light.xiongxiao.me:6443 K3S_TOKEN=K1035ea36d4925cfd0a7f7938fb3eff1225e458c1aee4fb99bda40bb95f529913bf::server:03e3ef7d17dadc2471b0f2369248250d sh - +--pause-image=docker.m.daocloud.io/rancher/mirrored-pause:3.9 + + +kubectl label nodes aliyun machine=aliyun --overwrite + +``` + +手动创建配置文件 +```sh +# 停止 k3s-agent 服务 +sudo systemctl stop k3s-agent + +# 编辑配置文件 +sudo vim /etc/systemd/system/k3s-agent.service.env + +# 重新加载 systemd 配置 +sudo systemctl daemon-reload + +# 启动服务 +sudo systemctl start k3s-agent +``` \ No newline at end of file diff --git a/k8s/xiongxiao.me/config/registry.md b/k8s/xiongxiao.me/config/registry.md index db8162a..0ddc99e 100644 --- a/k8s/xiongxiao.me/config/registry.md +++ b/k8s/xiongxiao.me/config/registry.md @@ -63,11 +63,11 @@ sudo systemctl restart containerd sudo ctr image pull docker.io/library/verdaccio:latest # K3s 使用 k8s.io 命名空间 -sudo ctr -n k8s.io images pull docker.m.daocloud.io/rancher/mirrored-pause:3.6 +sudo ctr -n k8s.io images pull docker.m.daocloud.io/rancher/mirrored-pause:3.9 -sudo ctr -n k8s.io images tag docker.m.daocloud.io/rancher/mirrored-pause:3.6 docker.io/rancher/mirrored-pause:3.6 +sudo ctr -n k8s.io images tag docker.m.daocloud.io/rancher/mirrored-pause:3.9 docker.io/rancher/mirrored-pause:3.9 -sudo ctr -n k8s.io images delete docker.m.daocloud.io/rancher/mirrored-pause:3.6 +sudo ctr -n k8s.io images delete docker.m.daocloud.io/rancher/mirrored-pause:3.9 # 查看镜像 diff --git a/k8s/xiongxiao.me/docs/00-master.md b/k8s/xiongxiao.me/docs/00-master.md index 5272afc..2cdea87 100644 --- a/k8s/xiongxiao.me/docs/00-master.md +++ b/k8s/xiongxiao.me/docs/00-master.md @@ -10,7 +10,9 @@ sudo cat /var/lib/rancher/k3s/server/node-token ## 2. 安装 node ```sh -curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh - +curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | + INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh - - \ + --system-default-registry=registry.cn-hangzhou.aliyuncs.com ``` ## 3. 删除 diff --git a/k8s/xiongxiao.me/test/hello/hello.yaml b/k8s/xiongxiao.me/test/hello/hello.yaml new file mode 100644 index 0000000..6803122 --- /dev/null +++ b/k8s/xiongxiao.me/test/hello/hello.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-world + labels: + app: hello-world +spec: + selector: + matchLabels: + app: hello-world + template: + metadata: + labels: + app: hello-world + spec: + nodeSelector: + machine: aliyun + containers: + - name: hello + image: docker.cnb.cool/kevisual/hello + ports: + - containerPort: 80 + protocol: TCP +--- +apiVersion: v1 +kind: Service +metadata: + name: hello-world + labels: + app: hello-world +spec: + selector: + app: hello-world + ports: + - protocol: TCP + port: 80 + targetPort: 80 + nodePort: 30081 + type: NodePort + +# http://121.199.37.154:30081/ + +# 1.查看 Deployment 状态: +# kubectl get deployment hello-world +# kubectl logs deployment/hello-world +# 2. 查看 Pod 状态: +# kubectl get pods -l app=hello-world + +# 3.查看 Pod 详细信息(包括事件): +# kubectl describe pod -l app=hello-world + +# 4. delete all +# kubectl delete -f hello.yaml + +# 5. delete pod +# kubectl delete pod -l app=hello-world + +# 6. rollupdate +# kubectl set image deployment/hello-world hello=docker.cnb.cool/kevisual/hello:latest + +# 7. 进入 Pod +# kubectl exec -it deployment/hello-world -- /bin/sh \ No newline at end of file