yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: 
  labels:
    app:  #选择器名称
  # #namespace: default 
spec:
  replicas: 1  #pod数量
  selector:         #标签选择器
    matchLabels:    #查找匹配的标签
      app:    #选择使用此标签
  template:         #Pod的模板信息,根据模板信息来创建Pod
    metadata:       #Pod的元数据
      labels:       #Pod的标签
        app:  #选择器名称
    spec:           #容器的信息
      containers:
      - name: nginx11
        image: nginx:1.21.6-alpine
        workingDir: string  #容器的工作目录
        ports:
        - containerPort: 80
        - containerPort: 8080
        env: 
        - name: TZ
          value: Asia/Shanghai
        - name: MYSQL_ROOT_PASSWORD
          value: xxxxxx
        command: 
        - sh
        - -c
        - "exec mongod -f /etc/mongo/mongod.conf"
        args: ['--default-auth=mysql_native_password','--max_connections=5000']
        volumeMounts: #k8s的master服务器对应的路径,必须存在    
        - name: confd
          mountPath: /etc/nginx/conf.d
          readOnly: true  #只读模式
      #resources: #资源限制和请求的设置
      #  limits:  #资源限制的设置
      #    cpu: string     #Cpu的限制,单位为core数,将用于docker run --cpu-shares参数
      #    memory: string  #内存限制,单位可以为Mib/Gib,将用于docker run --memory参数
      #  requests: #资源请求的设置
      #    cpu: string    #Cpu请求,容器启动的初始可用数量
      #    memory: string #内存请求,容器启动的初始可用数量 
      nodeName: node4
      restartPolicy: [Always | Never | OnFailure]
      nodeSelector: obeject #将该Pod调度到包含这个label的node上
      imagePullSecrets: #Pull镜像时使用的secret名称,以key:secretkey格式指定
      #hostNetwork: false   #是否使用主机网络模式,默认为false,如果设置为true,表示使用宿主机网络
      volumes:
        - name: confd
          #emptyDir:        #类型为emtyDir的存储卷,与Pod同生命周期的一个临时目录。为空值
          hostPath:
            path: /data/ngx/conf.d
---
apiVersion: v1
kind: Service
metadata: 
  name: 
  # #namespace: default
spec: 
  type: NodePort #配置为NodePort,外部可以访问
  selector:
    app:    #选择器
  ports:
    - name: http
      port: 80       #容器间,服务调用的端口
      targetPort: 80    #容器暴露的端口,与Dockerfile暴露端口保持一致
      nodePort:    #NodePort,外部访问的端口
      #protocol: TCP    #协议