Kubernetes: Configure Deployment to mount directory from local Kubernetes host?

7/18/2017

I need to provide access to the file /var/docker.sock on the Kubernetes host (actually, a GKE instance) to a container running on that host.

To do this I'd like to mount the directory into the container, by configuring the mount in the deployment.yaml for the container deployment.

How would I specify this in the deployment configuration?

Here is the current configuration, I have for the deployment:

apiVersion: apps/v1beta1
 kind: Deployment
metadata:
   name: appd-sa-agent
 spec:
  replicas: 1
   template: 
     metadata:
      labels:
        run: appd-sa-agent
     spec:
      containers:
      - name: appd-sa-agent
        image: docker.io/archbungle/appd-sa-agent:latest
        ports:
        - containerPort: 443
        env:
        - name: APPD_HOST  
          value: "https://graffiti201707132327203.saas.appdynamics.com"

How would I specify mounting the localhost file path to a directory mountpoint on the container?

Thanks! T.

-- Traiano Welcome
google-kubernetes-engine
kubernetes

2 Answers

7/18/2017

you need to use the hostPath option. Here is the sample yaml file.

https://kubernetes.io/docs/concepts/storage/volumes/#hostpath

-- sfgroups
Source: StackOverflow

7/18/2017

You need to define a hostPath volume.

apiVersion: apps/v1beta1
kind: Deployment
metadata:
   name: appd-sa-agent
 spec:
  replicas: 1
   template: 
     metadata:
      labels:
        run: appd-sa-agent
     spec:
      volumes:
      - name: docker-socket
        hostPath:
          path: /var/run/docker.sock
      containers:
      - name: appd-sa-agent
        image: docker.io/archbungle/appd-sa-agent:latest
        volumeMounts:
        - name: docker-socket
          mountPath: /var/run/docker.sock
        ports:
        - containerPort: 443
        env:
        - name: APPD_HOST  
          value: "https://graffiti201707132327203.saas.appdynamics.com"
-- Janos Lenart
Source: StackOverflow