apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: ngx1
  namespace: nginx
  #namespace: default
spec:
  replicas: 1 #k8s中要启动的pod个数,可以任意修改
  selector:
    matchLabels:
      app: nginx-v21
  template:
    metadata:
      labels:
        app: nginx-v21
    spec:
      containers:
      - name: nginx-v21
        image: nginx:1.21.5-alpine
        ports:
        - containerPort: 80
        - containerPort: 8080
        volumeMounts: #k8s的master服务器对应的路径,必须存在
        - name: confd
          mountPath: /etc/nginx/conf.d
        - name: conf
          mountPath: /etc/nginx/nginx.conf
        - name: log
          mountPath: /var/log/nginx
        - name: html
          mountPath: /etc/nginx/html
      volumes:
        - name: confd
          hostPath:
            path: /data/ngx/conf.d
        - name: conf
          hostPath:
            path: /data/ngx/nginx.conf
        - name: log
          hostPath:
            path: /data/ngx/logs
        - name: html
          hostPath:
            path: /data/ngx/html

---
apiVersion: v1
kind: Service  
metadata: 
 name: ngx1
 namespace: nginx
spec: 
  type: NodePort #配置为NodePort,外部可以访问
  ports:
    - name: http
      port: 80       #容器间,服务调用的端口
      targetPort: 80    #容器暴露的端口,与Dockerfile暴露端口保持一致
      nodePort: 30080   #NodePort,外部访问的端口
    - name: http2
      port: 8080
      targetPort: 8080
      nodePort: 30088
  selector:
    app: nginx-v21