如何在Kubernetes中部署Nginx.config文件

八荒 发表于: 2019-10-16   最后更新时间: 2019-10-16 23:13:58   3,824 游览

最近,我开始研究Kubernetes,我可以使用默认选项部署nginx。但是,如何在Kubernetes中部署我自己nginx.conf? 有人可以举一个简单的例子吗?

发表于 2019-10-16

创建nginx的deployment yaml:

kubectl run --image=nginx nginx -oyaml --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: {}

配置创建Nginx的Config ConfigMap

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
八荒 -> 半兽人 4年前

感谢,挂载文件亮了!!

你的答案

查看kubernetes相关的其他问题或提一个您自己的问题