zoukankan      html  css  js  c++  java
  • 多个pod共享一个volume

    1.yaml文件

    [root@k8s-matser01 nfs.rbac]# cat  nginx.yaml 
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      ports:
      - port: 80
        name: web
      selector:
        app: nginx
      type: ClusterIP
    ---
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: nginx-share-pvc
    spec:
      storageClassName: managed-nfs-storage 
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 1Gi
    ---
    apiVersion: apps/v1
    kind: Deployment 
    metadata:
      name: web
    spec:
      selector:
        matchLabels:
          app: nginx # has to match .spec.template.metadata.labels
      replicas: 3 # by default is 1
      template:
        metadata:
          labels:
            app: nginx # has to match .spec.selector.matchLabels
        spec:
          containers:
          - name: nginx
            image: nginx 
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 80
              name: web
            volumeMounts:
            - name: www
              mountPath: /usr/share/nginx/html
          volumes:
            - name: www
              persistentVolumeClaim:
                claimName: nginx-share-pvc
    

    其他容器查看

    [root@k8s-matser01 ~]# kubectl get pod |grep web
    web-7bf54cbc8d-b2wwp                      1/1     Running   0          8m10s
    web-7bf54cbc8d-pz4f4                      1/1     Running   0          8m10s
    web-7bf54cbc8d-tw9wg                      1/1     Running   0          8m10s
    
    [root@k8s-matser01 ~]# kubectl exec -it web-7bf54cbc8d-b2wwp -- /bin/bash
    
    root@web-7bf54cbc8d-pz4f4:/# echo $(date) > /usr/share/nginx/html/index.html
    
    root@web-7bf54cbc8d-pz4f4:/# cat /usr/share/nginx/html/index.html
    Mon Nov 15 05:33:56 UTC 2021
    
    

    3.其他容器查看

    [root@k8s-matser01 ~]# kubectl exec web-7bf54cbc8d-pz4f4 -- cat /usr/share/nginx/html/index.html
    Mon Nov 15 05:33:56 UTC 2021
    
    [root@k8s-matser01 ~]# kubectl exec web-7bf54cbc8d-tw9wg -- cat /usr/share/nginx/html/index.html
    Mon Nov 15 05:33:56 UTC 2021
    
    
  • 相关阅读:
    第四次作业
    软工第三次作业
    第三次作业
    第二次作业
    团队第三次作业:Alpha版本发布
    软件工程团队作业--Alpha版本第二周小结
    软件工程团队作业--Alpha版本第一周小结
    团队第二次作业
    C++多态性总结
    第四次作业:结对编程
  • 原文地址:https://www.cnblogs.com/Applogize/p/15555892.html
Copyright © 2011-2022 走看看