部署一个简单的pod(nginx)

#部署
kubectl create -f ngx-php-pod.yaml 
kubectl apply -f pod_ngx.yaml 

重启一
kubectl delete pod ngx3    #命令空间    -n nginx
kubectl apply -f pod_ngx.yaml 
重启方式二
kubectl replace --force -f pod-ngxphp.yaml

#查看
kubectl get pods   #命令空间-n nginx
kubectl get pod -o wide         --namespace=nginx
kubectl get pod --all-namespaces #所有命名空间

kubectl describe pod ngx-php  #查看详细
kubectl logs ngx-php        -c init-myservice  #查看日志
crictl ps 子容器运行的详细位置

测试

kubectl get pod -o wide 
curl http://100.68.225.68

nginx【yaml文件】

apiVersion: v1
kind: Pod
metadata:
  #labels:           #自定义标签列表
  #  - name: nginx3     
  #  app: nginx     #或者这样
  name: ngx3
  #namespace: nginx 
spec:
  containers:
  - name: ngx
    image: nginx:1.21.5-alpine
    #imagePullPolicy: [ Always每次都拉|Never从不拉|IfNotPresent 宿主不存在才拉取 ]  #获取镜像的策略 
    #command: [string]   #容器的启动命令列表,如不指定,使用打包时使用的启动命令
    #args: [string]      #容器的启动命令参数列表
    #workingDir: string  #容器的工作目录
    ports:
    - containerPort: 80
    - containerPort: 8080
    #- name: string        #端口的名称
    #  containerPort: int  #容器需要监听的端口号
    #  hostPort: int       #容器所在主机需要监听的端口号,默认与Container相同
    #  protocol: string    #端口协议,支持TCP和UDP,默认TCP
    #env:   #容器运行前需设置的环境变量列表
    #- name: string  #环境变量名称
    #  value: string #环境变量的值
    volumeMounts: #k8s的master服务器对应的路径,必须存在
    - name: confd
      mountPath: /etc/nginx/conf.d
    - name: conf
      mountPath: /etc/nginx/nginx.conf
      #readOnly: boolean #是否为只读模式
    - name: fastcgi-php
      mountPath: /etc/nginx/fastcgi_php.conf
    - name: log
      mountPath: /var/log/nginx
    - name: html
      mountPath: /etc/nginx/html
    #resources: #资源限制和请求的设置
    #  limits:  #资源限制的设置
    #    cpu: string     #Cpu的限制,单位为core数,将用于docker run --cpu-shares参数
    #    memory: string  #内存限制,单位可以为Mib/Gib,将用于docker run --memory参数
    #  requests: #资源请求的设置
    #    cpu: string    #Cpu请求,容器启动的初始可用数量
    #    memory: string #内存请求,容器启动的初始可用数量 
  #restartPolicy: [Always | Never | OnFailure 异常退出时重启,退出状态码非0]  #Pod的重启策略
  nodeName: node8  #将该Pod调度到指定到名称的node节点上
  #nodeSelector: obeject #将该Pod调度到包含这个label的node上
  #imagePullSecrets: #Pull镜像时使用的secret名称,以key:secretkey格式指定
  #- name: string
  #hostNetwork: false   #是否使用主机网络模式,默认为false,如果设置为true,表示使用宿主机网络
  volumes:
    - name: confd
      #emptyDir:        #类型为emtyDir的存储卷,与Pod同生命周期的一个临时目录。为空值
      hostPath:
        path: /data/ngx/conf.d
    - name: conf
      hostPath:
        path: /data/ngx/nginx.conf
    - name: fastcgi-php
      hostPath:
        path: /data/ngx/fastcgi_php.conf
    - name: log
      hostPath:
        path: /data/ngx/logs
    - name: html
      hostPath:
        path: /data/ngx/html         
      #secret:          #类型为secret的存储卷,挂载集群与定义的secret对象到容器内部
      # scretname: string  
      #  items:     
      #  - key: string
      #      path: string
      #configMap:         #类型为configMap的存储卷,挂载预定义的configMap对象到容器内部
      #  name: string
      #  items:
      #  - key: string
      #    path: string