Kubernetes:配置部署以从本地Kubernetes主机挂载目录?

时间:2017-07-18 11:44:03

标签: kubernetes google-kubernetes-engine

我需要访问Kubernetes主机上的文件/var/docker.sock(实际上是一个GKE实例)到该主机上运行的容器。

为此,我想通过在deployment.yaml中为容器部署配置mount来将目录挂载到容器中。

我如何在部署配置中指定此内容?

以下是我对部署的当前配置:

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"

如何指定将localhost文件路径挂载到容器上的目录挂载点?

谢谢! 吨。

2 个答案:

答案 0 :(得分:3)

您需要定义hostPath卷。

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"

答案 1 :(得分:0)

您需要使用hostPath选项。这是示例yaml文件。

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