K8s部署Nginx容器+端口映射

这里涉及到了证书挂载和启动配置文件的挂载,需要配置正确

  • 挂载启动配置和证书

  • 执行下面的yml配置即可部署成功
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web-nginx
  template:
    metadata:
      labels:
        app: web-nginx
    spec:
      containers:
        - name: web-nginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: web-nginx-config
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
            - name: nginx-cert-volume
              mountPath: /etc/nginx/certs
      volumes:
        - name: web-nginx-config
          configMap:
            name: nginx-config
        - name: nginx-cert-volume
          secret:
            secretName: nginx-cert
---
apiVersion: v1
kind: Service
metadata:
  name: web-nginx
  labels:
    app: web-nginx
spec:
  type: NodePort
  selector:
    app: web-nginx
  ports:
    - name: second-routing
      nodePort: 30008
      port: 90
      targetPort: 443
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。