I was trying to setup Jenkins in Rancher server using NFS (Shared storage) I ran into many issues and finally solved it. Thought will share the steps so that others will benefit.
1) Before getting started with, make sure you have hosts setup in Rancher Environment.
2) Next follow this steps on this link: Rancher-Nfs Prerequiiste
3) Click on Catalog menu in Rancher server and search for nfs
Click on view details button.
4) You will see a screen like below. Enter the details as seen in screenshot. HostIP will be your NFS server.
Note : The export base directory should be same as the directory you created as part of Step 2. Click on launch button.
5) Navigate to Infrastructure tab to double check storage driver is active.
6) Now proceed to Stack menu and create a stack.
I will be creating a Jenkins stack.
docker-compose.yml
version: '2'
volumes:
jenkins-var-jenkins:
driver: rancher-nfs
jenkins-etc-ssl-certs:
driver: rancher-nfs
services:
Jenkins:
image: jenkins:2.60.2
stdin_open: true
volumes:
- jenkins-var-jenkins:/var/jenkins_home
- jenkins-etc-ssl-certs:/etc/ssl/certs
tty: true
Jenkins-LB:
image: rancher/lb-service-haproxy:v0.7.5
ports:
- 8080:8080/tcp
labels:
io.rancher.container.agent.role: environmentAdmin
io.rancher.container.create_agent: 'true'
rancher-compose.yml
version: '2'
services:
Jenkins:
scale: 2
start_on_create: true
Jenkins-LB:
scale: 1
start_on_create: true
lb_config:
certs: []
port_rules:
- path: ''
priority: 1
protocol: http
service: Jenkins
source_port: 8080
target_port: 8080
7) You may see an error like in the screenshot below.
8) Go to your host machine and edit /etc/exports and add "no_root_squash" to the mount option.
It will look like
/nfs *(rw,sync,no_subtree_check,no_root_squash)
9) Restart the nfs-server with command.
systemctl restart nfs-server ( It varies on linux versions)
10) Delete and recreate the stack as per Step 6
11) A jenkins stack with load balancer will be created and accessible now.
Note: You can check my github repo for the code. Jenkins-Rancher-Catalog
The complete solution is explained in the above article.