码迷,mamicode.com
首页 > 其他好文 > 详细

查找pod使用的物理目录位置

时间:2020-02-08 15:33:54      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:hub   vol   volumes   rest   amp   物理   ansi   res   ota   

例子:找出当前pod挂载的是哪个物理目录

# 先查看pod web-0 的yaml文件
# kubectl get pod web-0 -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2020-02-07T12:06:07Z"
  generateName: web-
  labels:
    app: nginx
    controller-revision-hash: web-8d6d99dc7
    statefulset.kubernetes.io/pod-name: web-0
  name: web-0
  namespace: default
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: StatefulSet
    name: web
    uid: fb8eb881-a311-426f-8734-17457effaa12
  resourceVersion: "524897"
  selfLink: /api/v1/namespaces/default/pods/web-0
  uid: ea5ff673-2791-4ee1-8ec2-713516e1bd9d
spec:
  containers:
  - image: hub.zhoushiya.top/test/nginx
    imagePullPolicy: IfNotPresent
    name: nginx
    ports:
    - containerPort: 80
      name: web
      protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: www
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-75xfr
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  hostname: web-0
  nodeName: k8s-node01
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  subdomain: nginx
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: www   #确定此处挂载的目录是www
    persistentVolumeClaim:
      claimName: www-web-0  #使用的pvc名称叫做www-web-0
  - name: default-token-75xfr
    secret:
      defaultMode: 420
      secretName: default-token-75xfr
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2020-02-07T12:06:26Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2020-02-07T12:06:28Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2020-02-07T12:06:28Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2020-02-07T12:06:09Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://5ada7f2cfa1bdd4520b15de6efeae1fc96f0a98596a55e8dae349ddb4894a339
    image: hub.zhoushiya.top/test/nginx:latest
    imageID: docker-pullable://hub.zhoushiya.top/test/nginx@sha256:401ff5d136d690b2eaf61055aabdb7b4bc2ed8114fb5e423963249db7ac0188e
    lastState: {}
    name: nginx
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2020-02-07T12:06:28Z"
  hostIP: 192.168.66.20
  phase: Running
  podIP: 10.244.1.67
  podIPs:
  - ip: 10.244.1.67
  qosClass: BestEffort
  startTime: "2020-02-07T12:06:26Z"
# 确定了pvc叫做www-web-0,再去查看pvc的yaml
# kubectl get pvc www-web-0
NAME        STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
www-web-0   Bound    nfspv2   2Gi        RWO            nfs            17h
# 确定了现在使用的pv是nfspv2,再去查看pv nfspv2的yaml
# kubectl get pv nfspv2 -o yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"name":"nfspv2"},"spec":{"accessModes":["ReadWriteOnce"],"capacity":{"storage":"2Gi"},"nfs":{"path":"/nfsdata2","server":"192.168.66.100"},"persistentVolumeReclaimPolicy":"Retain","storageClassName":"nfs"}}
    pv.kubernetes.io/bound-by-controller: "yes"
  creationTimestamp: "2020-02-07T11:14:36Z"
  finalizers:
  - kubernetes.io/pv-protection
  name: nfspv2
  resourceVersion: "524873"
  selfLink: /api/v1/persistentvolumes/nfspv2
  uid: c239574e-387c-4532-a1ee-5e9c8a8b8376
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 2Gi
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: www-web-0
    namespace: default
    resourceVersion: "524868"
    uid: b4674789-dd10-4d01-99bf-ebc69dde5dad
  nfs:
    path: /nfsdata2 #这就是使用的目录了
    server: 192.168.66.100  #这是目录的主机
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs
  volumeMode: Filesystem
status:
  phase: Bound

可以看到最后结果是192.168.66.100:/nfsdata2/目录挂载到了pod的/usr/share/nginx/html/下面

查找pod使用的物理目录位置

标签:hub   vol   volumes   rest   amp   物理   ansi   res   ota   

原文地址:https://www.cnblogs.com/zhoushiya/p/12283184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!