docs(content): harden Kubernetes and supply-chain examples

This commit is contained in:
yeasy
2026-05-22 00:53:38 -07:00
parent 8b9e4518c8
commit ec0fa15835
4 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
Kubernetes 的最小调度单位是 `Pod`一个 `Pod` 由一组紧密协作的容器构成它们共享网络命名空间IP 以及部分存储资源也可以根据需要对 Pod 进行端口映射
如果你已经熟悉 Docker可以用以下对照来理解 Kubernetes 的核心概念Docker 中的"容器"对应 Kubernetes `Pod`一个或多个容器的组合`docker-compose.yml` 的角色类似于 Kubernetes `Deployment` + `Service` 声明`docker run` 的端口映射和网络配置 Kubernetes 中由 `Service` `Ingress` 接管掌握这些映射关系有助于从单机 Docker 平滑过渡到集群编排
如果你已经熟悉 Docker可以用以下对照来理解 Kubernetes 的核心概念Docker 中的容器对应 Kubernetes `Pod`一个或多个容器的组合`docker-compose.yml` 的角色类似于 Kubernetes `Deployment` + `Service` 声明`docker run` 的端口映射和网络配置 Kubernetes 中由 `Service` `Ingress` 接管掌握这些映射关系有助于从单机 Docker 平滑过渡到集群编排
本章将分为 5 节介绍 `Kubernetes`
+4 -2
View File
@@ -68,9 +68,11 @@ $ sudo apt-get install uidmap
$ su - testuser
```
3. 运行 Docker 官方提供的 Rootless 安装脚本
3. 下载并检查 Docker 官方提供的 Rootless 安装脚本确认来源和内容后再执行
```bash
$ curl -fsSL https://get.docker.com/rootless | sh
$ curl -fsSL https://get.docker.com/rootless -o install-rootless-docker.sh
$ less install-rootless-docker.sh
$ sh install-rootless-docker.sh
```
4. 配置环境变量指向新创建的私有 socket
+8 -10
View File
@@ -502,29 +502,29 @@ variables:
build:
stage: build
image: docker:latest
image: docker:<version>-cli@sha256:<docker-cli-digest>
services:
- docker:dind
- name: docker:<version>-dind@sha256:<docker-dind-digest>
script:
- docker build -t $IMAGE_NAME:$CI_COMMIT_SHA .
- docker save $IMAGE_NAME:$CI_COMMIT_SHA > image.tar
scan:trivy:
stage: scan
image: aquasec/trivy:latest
image: aquasec/trivy:<version>@sha256:<trivy-digest>
script:
- trivy image --severity HIGH,CRITICAL --exit-code 1 docker-archive://image.tar
allow_failure: false
scan:grype:
stage: scan
image: anchore/grype:latest
image: anchore/grype:<version>@sha256:<grype-digest>
script:
- grype docker-archive://image.tar
generate:sbom:
stage: scan
image: anchore/syft:latest
image: anchore/syft:<version>@sha256:<syft-digest>
script:
- syft docker-archive://image.tar -o cyclonedx > sbom.xml
artifacts:
@@ -533,9 +533,9 @@ generate:sbom:
push:
stage: push
image: docker:latest
image: docker:<version>-cli@sha256:<docker-cli-digest>
services:
- docker:dind
- name: docker:<version>-dind@sha256:<docker-dind-digest>
script:
- docker load < image.tar
- echo "$REGISTRY_PASSWORD" | docker login --username "$REGISTRY_USER" --password-stdin "$REGISTRY"
@@ -550,13 +550,11 @@ push:
sign:
stage: sign
image: gcr.io/projectsigstore/cosign:latest
image: gcr.io/projectsigstore/cosign:<version>@sha256:<cosign-digest>
script:
- cosign sign --key $COSIGN_KEY "$(cat image-digest.txt)"
only:
- main
only:
- main
```
### 18.6.6 常见问题与最佳实践
+2 -1
View File
@@ -66,7 +66,8 @@ deploy_staging:
stage: deploy
image: dtzar/helm-kubectl
script:
- kubectl config set-cluster k8s --server=$KUBE_URL --insecure-skip-tls-verify=true
- printf '%s' "$KUBE_CA_PEM" > kube-ca.crt
- kubectl config set-cluster k8s --server=$KUBE_URL --certificate-authority=kube-ca.crt --embed-certs=true
- kubectl config set-credentials admin --token=$KUBE_TOKEN
- kubectl config set-context default --cluster=k8s --user=admin
- kubectl config use-context default