gpt4 book ai didi

linux - 如何在 kubernetes 中部署 nginx.config 文件

转载 作者:太空宇宙 更新时间:2023-11-04 04:39:25 24 4
gpt4 key购买 nike

最近我开始学习 Kubernetes,现在我可以使用默认选项部署 nginx。但是我如何在 Kubernetes 中部署 nginx.conf 呢?也许有人有一个简单的例子?

最佳答案

为 nginx 部署创建 yaml:

kubectl run --image=nginx nginx -o yaml --dry-run
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
run: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
run: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}

创建配置ConfigMap与 nginx 配置

kubectl create configmap nginx-conf --from-file=./nginx.conf

挂载文件:

apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
run: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
run: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
volumeMounts:
- mountPath: /etc/nginx/nginx.conf
name: nginx-conf
subPath: nginx.conf
volumes:
- configMap:
name: nginx-conf
name: nginx-conf

关于linux - 如何在 kubernetes 中部署 nginx.config 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com