kubernetes - 使用 gitlab 在 pod 内的多个容器中安装 kubernetes 卷
问题描述
我第一次设置了一个由单节点 kubernetes (minikube) 组成的 CI/CD 环境。
在这个节点上我创建了一个 PV
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
data-volume 1Gi RWO Retain Bound gitlab-managed-apps/data-volume-claim manual 20m
和聚氯乙烯
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-volume-claim Bound data-volume 1Gi RWO manual 19m
现在我想创建一个具有多个容器访问此卷的 pod。
您建议在哪里以及如何使用 gitlab 管道 gitlab-ci 等进行设置?多个存储库可能最适合该项目。
解决方案
这是部署清单文件的完整工作示例,在 Pod 的规范中使用相同的 PV 定义了两个容器(基于不同的 nginx docker 映像),它们相应地在端口 80/81 上提供自定义静态 html 内容:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: null
generation: 1
labels:
run: nginx
name: nginx
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/nginx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
run: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: nginx
spec:
volumes:
- name: my-pv-storage
persistentVolumeClaim:
claimName: my-pv-claim-nginx
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: my-pv-storage
subPath: html_custom
- image: custom-nginx
imagePullPolicy: IfNotPresent
name: custom-nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: my-pv-storage
subPath: html
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
推荐阅读
- scala - 什么时候有 2.13 的 sbt 版本?
- c++ - std::optional::emplace() 默认构造一个可选在clang中不起作用?
- html - 减少边框长度
- sql - 如何修复 Postgres 12 错误:CASE 中不允许设置返回函数
- sql-loader - 在 SQL 加载器中跳过输入文件中的多列
- java - 组 - 从数据框中的 2 列计数 - Spark Java
- mongodb - 如何在 Doctrine ODM 中创建 GeoJson 多边形
- python - Openpyxl - 在不同的工作表上创建图表
- mysql - 如何使用 Django 为我的 MYSQL 数据库实现数据库分片
- swift - How to make a UIView gradient effect using 3 colors