hostPath as volume in kubernetes

前端 未结 1 1413
长发绾君心
长发绾君心 2021-02-14 00:05

I am trying to configure hostPath as the volume in kubernetes. I have logged into VM server, from where I usually use kubernetes commands such as kubectl.

Below is the p

1条回答
  •  臣服心动
    2021-02-14 00:59

    hostPath type volumes refer to directories on the Node (VM/machine) where your Pod is scheduled for running (aks-nodepool1-39499429-1 in this case). So you'd need to create this directory at least on that Node.

    To make sure your Pod is consistently scheduled on that specific Node you need to set spec.nodeSelector in the PodTemplate:

    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: helloworldanilhostpath
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            run: helloworldanilhostpath
        spec:
          nodeSelector:
            kubernetes.io/hostname: aks-nodepool1-39499429-1
          volumes:
            - name: task-pv-storage
              hostPath:
                path: /home/openapianil/samplePV
                type: Directory
          containers:
          - name: helloworldv1
            image: ***/helloworldv1:v1
            ports:
            - containerPort: 9123
            volumeMounts:
             - name: task-pv-storage
               mountPath: /mnt/sample
    

    In most cases it's a bad idea to use this type of volume; there are some special use cases, but chance are yours is not one them!

    If you need local storage for some reason then a slightly better solution is to use local PersistentVolumes.

    0 讨论(0)
提交回复
热议问题