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

标签 linux docker kubernetes

最近我开始学习 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/

相关文章:

kubernetes - 大使API网关不提供服务

linux - 在 Linux 中的大型单行文件 (~2GB) 文件中搜索和替换

linux - 简单与神秘的用户名

linux - 在 linux 内核 3.12 中使用 leds-pwm susbsystem 控制 LED

docker - 如何连接到在 docker hub 上的镜像上运行的 Web 应用程序?

angular - 如何编写正确的 yaml 以在 Azure Devops 中部署 kubernetes 集群?

linux - Linux 的 Visual Foxpro dBASE/dbf 类型解决方案

使用 sudo 时无法识别 docker compose

docker - 在没有 Kubernetes 的本地开发环境中运行 Ambassador

amazon-web-services - 从Kubernetes HA群集安全删除主服务器