Jenkins-slave "Cannot write to volume error" on kubernetes

10/2/2017

I am setting up my jenkins on kubernetes via helm to run my java deployment,

This spawns new pods for every build -> fair enough

Then I see that I need to store some maven jars which will be used by other builds,

So I came up with NFS installation and mounted it to /home/jenkins/.m2 via jenkins configure (Web console)

Then I keep getting the

error org.apache.maven.repository.LocalRepositoryNotAccessibleException: Could not create local repository at /home/jenkins/.m2/repository

I even tried

securityContext: runAsUser: 1000 fsGroup: 1000 in the deployment.yaml

I tried adding

USER root RUN chown -R root /home/jenkins

in the slave container

Its just not with the .m2 , slave is not able to write anything on this pvc.

At this point I’m confused where else the problem could be. can some one please help?

-- Karthik
jenkins
kubernetes
kubernetes-helm

1 Answer

2/7/2019

I had similar issue. I solved this way:

  • made own jnlp image, modified, with maven installed on it
  • i moved m2 out of jenkins home directory into /opt/m2 through maven configuration
  • created persistent disk, and bounded pv and pvc with it and mounted on /opt/m2 inside pod
  • and last, I set inside Dockerfile for jnlp that User running image is ROOT, since every mount on kubernetes is mounted as root. Not very elegant but working solution
-- jovan
Source: StackOverflow