Naming gitRepo mount path in Kubernetes

10/9/2015

When using a gitRepo volume in Kubernetes, the repo is cloned into the mountPath directory. For the following pod specification, for example:

apiVersion: v1
kind: Pod
metadata:
  name: server
spec:
  containers:
  - image: nginx
    name: nginx
    volumeMounts:
    - mountPath: /usr/share/docroot
      name: docroot-volume
  volumes:
  - name: docroot-volume
    gitRepo:
      repository: "git@somewhere:me/my-git-repository.git"

The directory appears in the container at /usr/share/docroot/my-git-repository. This means my container needs to know my repository name. I don't want my container knowing anything about the repository name. It should just know there is a "docroot", however initialized. The only place the git repository name should appear is in the pod specification.

Is there anyway in Kubernetes to specify the full internal path to a git repo volume mount?

-- Bradley
kubernetes

1 Answer

10/10/2015

Currently there is no native way to do this, but I filed an issue for you.

Under the hood kuberetes is just doing a git clone $source over an emptyDir volume, but since the source is passed as a single argument there is no way to specify the destination name.

Fri, 09 Oct 2015 18:35:01 -0700 Fri, 09 Oct 2015 18:49:52 -0700 90  {kubelet stclair-minion-nwpu}       FailedSync  Error syncing pod, skipping: failed to exec 'git clone https://github.com/kubernetes/kubernetes.git k8s': Cloning into 'kubernetes.git k8s'...
error: The requested URL returned error: 400 while accessing https://github.com/kubernetes/kubernetes.git k8s/info/refs
fatal: HTTP request failed
: exit status 128

In the meantime, I can think of 2 options to avoid the dependency on the repository name:

  1. Supply the repository name as an environment variable, which you can then use from your container
  2. Modify your containers command to move the repository to the desired location before continuing
-- Tim Allclair
Source: StackOverflow