fix(content): harden copy-paste safety examples

This commit is contained in:
yeasy
2026-05-27 18:17:24 -07:00
parent 3a9ee19d22
commit f09e800020
4 changed files with 30 additions and 20 deletions
+10 -6
View File
@@ -90,9 +90,11 @@ $ sudo dnf versionlock clear
##### 挂载 ISO 镜像搭建本地 File ##### 挂载 ISO 镜像搭建本地 File
```bash ```bash
## 删除其他网络源 ## 备份其他网络源
$ sudo rm -f /etc/yum.repos.d/* $ repo_backup="/etc/yum.repos.d/backup-$(date +%Y%m%d%H%M%S)"
$ sudo mkdir -p "$repo_backup"
$ sudo find /etc/yum.repos.d -maxdepth 1 -type f -name '*.repo' -exec mv {} "$repo_backup"/ \;
## 挂载光盘或者iso镜像 ## 挂载光盘或者iso镜像
@@ -106,7 +108,7 @@ $ sudo tee /etc/yum.repos.d/local-base.repo <<EOF
name=local_base name=local_base
baseurl=file:///mnt baseurl=file:///mnt
enabled=1 enabled=1
gpgcheck=0 gpgcheck=1
EOF EOF
``` ```
```bash ```bash
@@ -156,7 +158,9 @@ $ sudo createrepo_c /var/www/html/docker-ce/
##### DNF 客户端设置 ##### DNF 客户端设置
```bash ```bash
$ sudo rm -f /etc/yum.repos.d/* $ repo_backup="/etc/yum.repos.d/backup-$(date +%Y%m%d%H%M%S)"
$ sudo mkdir -p "$repo_backup"
$ sudo find /etc/yum.repos.d -maxdepth 1 -type f -name '*.repo' -exec mv {} "$repo_backup"/ \;
$ sudo tee /etc/yum.repos.d/local-files.repo <<EOF $ sudo tee /etc/yum.repos.d/local-files.repo <<EOF
[local_base] [local_base]
name=local_base name=local_base
@@ -165,7 +169,7 @@ name=local_base
baseurl=http://x.x.x.x/base baseurl=http://x.x.x.x/base
enabled=1 enabled=1
gpgcheck=0 gpgcheck=1
proxy=_none_ proxy=_none_
[docker-ce-stable] [docker-ce-stable]
name=docker-ce-stable name=docker-ce-stable
@@ -174,7 +178,7 @@ name=docker-ce-stable
baseurl=http://x.x.x.x/docker-ce baseurl=http://x.x.x.x/docker-ce
enabled=1 enabled=1
gpgcheck=0 gpgcheck=1
proxy=_none_ proxy=_none_
EOF EOF
+3 -1
View File
@@ -158,9 +158,11 @@ RUN --mount=type=cache,target=/go/pkg/mod \
```docker ```docker
RUN --mount=type=secret,id=mysecret \ RUN --mount=type=secret,id=mysecret \
cat /run/secrets/mysecret my-private-tool --token-file /run/secrets/mysecret
``` ```
不要在构建命令中 `cat``echo` 或打印密钥内容应把 `/run/secrets/<id>` 路径交给真正消费密钥的工具
#### 3. Heredoc 语法 #### 3. Heredoc 语法
BuildKit 支持使用 heredoc 语法编写多行脚本无需行末反斜杠 `\` 连接 BuildKit 支持使用 heredoc 语法编写多行脚本无需行末反斜杠 `\` 连接
+9 -7
View File
@@ -186,8 +186,8 @@ $ sudo kubeadm init \
```bash ```bash
... ...
[addons] Applied essential addon: CoreDNS [addons] Applied essential addon: CoreDNS
I1116 12:35:13.270407 86677 request.go:538] Throttling request took 181.409184ms, request: POST:https://192.168.199.100:6443/api/v1/namespaces/kube-system/serviceaccounts I1116 12:35:13.270407 86677 request.go:538] Throttling request took 181.409184ms, request: POST:https://<CONTROL_PLANE_HOST>:6443/api/v1/namespaces/kube-system/serviceaccounts
I1116 12:35:13.470292 86677 request.go:538] Throttling request took 186.088112ms, request: POST:https://192.168.199.100:6443/api/v1/namespaces/kube-system/configmaps I1116 12:35:13.470292 86677 request.go:538] Throttling request took 186.088112ms, request: POST:https://<CONTROL_PLANE_HOST>:6443/api/v1/namespaces/kube-system/configmaps
[addons] Applied essential addon: kube-proxy [addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully! Your Kubernetes control-plane has initialized successfully!
@@ -204,8 +204,8 @@ Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
Then you can join any number of worker nodes by running the following on each as root: Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.199.100:6443 --token cz81zt.orsy9gm9v649e5lf \ kubeadm join <CONTROL_PLANE_HOST>:6443 --token <TOKEN> \
--discovery-token-ca-cert-hash sha256:5edb316fd0d8ea2792cba15cdf1c899a366f147aa03cba52d4e5c5884ad836fe --discovery-token-ca-cert-hash sha256:<DISCOVERY_TOKEN_CA_CERT_HASH>
``` ```
#### node 工作节点 #### node 工作节点
@@ -217,12 +217,14 @@ $ systemctl enable containerd
$ systemctl start containerd $ systemctl start containerd
$ kubeadm join 192.168.199.100:6443 \ $ kubeadm join <CONTROL_PLANE_HOST>:6443 \
--token cz81zt.orsy9gm9v649e5lf \ --token <TOKEN> \
--discovery-token-ca-cert-hash sha256:5edb316fd0d8ea2792cba15cdf1c899a366f147aa03cba52d4e5c5884ad836fe \ --discovery-token-ca-cert-hash sha256:<DISCOVERY_TOKEN_CA_CERT_HASH> \
--cri-socket unix:///run/containerd/containerd.sock --cri-socket unix:///run/containerd/containerd.sock
``` ```
其中 `<CONTROL_PLANE_HOST>``<TOKEN>` `<DISCOVERY_TOKEN_CA_CERT_HASH>` 应使用你自己的 `kubeadm init` 输出不要复用示例值
### 14.1.7 查看服务 ### 14.1.7 查看服务
所有服务启动后通过 `crictl` 查看本地实际运行的容器这些服务大概分为三类主节点服务工作节点服务和其它服务 所有服务启动后通过 `crictl` 查看本地实际运行的容器这些服务大概分为三类主节点服务工作节点服务和其它服务
+8 -6
View File
@@ -213,8 +213,8 @@ $ sudo kubeadm init --image-repository registry.cn-hangzhou.aliyuncs.com/google_
```bash ```bash
... ...
[addons] Applied essential addon: CoreDNS [addons] Applied essential addon: CoreDNS
I1116 12:35:13.270407 86677 request.go:538] Throttling request took 181.409184ms, request: POST:https://192.168.199.100:6443/api/v1/namespaces/kube-system/serviceaccounts I1116 12:35:13.270407 86677 request.go:538] Throttling request took 181.409184ms, request: POST:https://<CONTROL_PLANE_HOST>:6443/api/v1/namespaces/kube-system/serviceaccounts
I1116 12:35:13.470292 86677 request.go:538] Throttling request took 186.088112ms, request: POST:https://192.168.199.100:6443/api/v1/namespaces/kube-system/configmaps I1116 12:35:13.470292 86677 request.go:538] Throttling request took 186.088112ms, request: POST:https://<CONTROL_PLANE_HOST>:6443/api/v1/namespaces/kube-system/configmaps
[addons] Applied essential addon: kube-proxy [addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully! Your Kubernetes control-plane has initialized successfully!
@@ -231,8 +231,8 @@ Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
Then you can join any number of worker nodes by running the following on each as root: Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.199.100:6443 --token cz81zt.orsy9gm9v649e5lf \ kubeadm join <CONTROL_PLANE_HOST>:6443 --token <TOKEN> \
--discovery-token-ca-cert-hash sha256:5edb316fd0d8ea2792cba15cdf1c899a366f147aa03cba52d4e5c5884ad836fe --discovery-token-ca-cert-hash sha256:<DISCOVERY_TOKEN_CA_CERT_HASH>
``` ```
#### node 工作节点 #### node 工作节点
@@ -240,11 +240,13 @@ kubeadm join 192.168.199.100:6443 --token cz81zt.orsy9gm9v649e5lf \
**另一主机** 重复 **部署** 小节以前的步骤安装配置好 kubelet根据提示加入到集群 **另一主机** 重复 **部署** 小节以前的步骤安装配置好 kubelet根据提示加入到集群
```bash ```bash
$ kubeadm join 192.168.199.100:6443 --token cz81zt.orsy9gm9v649e5lf \ $ kubeadm join <CONTROL_PLANE_HOST>:6443 --token <TOKEN> \
--discovery-token-ca-cert-hash sha256:5edb316fd0d8ea2792cba15cdf1c899a366f147aa03cba52d4e5c5884ad836fe \ --discovery-token-ca-cert-hash sha256:<DISCOVERY_TOKEN_CA_CERT_HASH> \
--cri-socket unix:///var/run/cri-dockerd.sock --cri-socket unix:///var/run/cri-dockerd.sock
``` ```
其中 `<CONTROL_PLANE_HOST>``<TOKEN>` `<DISCOVERY_TOKEN_CA_CERT_HASH>` 应使用你自己的 `kubeadm init` 输出不要复用示例值
### 14.2.7 查看服务 ### 14.2.7 查看服务
所有服务启动后查看本地实际运行的 Docker 容器这些服务大概分为三类主节点服务工作节点服务和其它服务 所有服务启动后查看本地实际运行的 Docker 容器这些服务大概分为三类主节点服务工作节点服务和其它服务