Step-by-step guide how to install Jenkins in the Kubernetes cluster and run Jenkins agents inside that cluster.
For minikube install ingress controller with following command:
minikube start -n 2
minikube addons enable ingress
kubectl create namespace jenkins
kubecl apply -f config/jenkins/service-account.yaml
kubectl apply -f config/jenkins/jenkins.yaml
kubectl apply -f jenkins-ingress.yaml
echo "$(minikube ip) jenkins.example.com" >> /etc/hosts
Navigate to 'Manage Jenkins' -> 'Manage Nodes and Clouds' -> 'Configure Clouds'
Press 'Add new cloud' and select 'Kubernetes'
Press 'Kubernetes Cloud details...' button to configure Kubernetes plugin
-
Under 'Kubernetes Namespace' write the namespace that was previously configured. In my case it is 'jenkins'. Press 'Test Connection' button - 'Connected to Kubernetes vX.XX.XX' should appear.
-
Config 'Jenkins URL' field. It should combined from following info:
http://<service-name>.<namespace>.svc.cluster.local:8080
. To check service name just issue following command:kubectl get svc -n jenkins
. In my case it looks as:http://jenkins-service.jenkins.svc.cluster.local:8080
-
Under 'Pod Labels' section press 'Add Pod Label' button and select 'Pod Label'. Fill 'Key' - 'Jenkins' and 'Value' - 'agent'
-
Under 'Pod Templates' press 'Add Pod Template' button and 'Pod Template Details...' button. Fill the following fields with info:
- 'Name' - 'kube-agent'
- 'Namespace' - 'jenkins'
- 'Labels' - 'kubeagent'
-
Under 'Containers' press 'Add Container' button and select 'Container Template'. Fill 'Name' - 'jnlp' and 'Docker image' - 'jenkins/inbound-agent:latest'. Remove values from 'Command to run' and 'Arguments to pass to the command' fields.
Now Jenkins will build jobs that have label 'kubeagent' inside container.
Prometheus:
clusterRole.yaml
config-map.yaml
prometheus-deployment.yaml
prometheus-service.yaml
prometheus-ingress.yaml
Grafana:
grafana-datasource-config.yaml
grafana-deployment.yaml
grafana-service.yaml
grafana-ingress.yaml
echo "$(minikube ip) prometheus.example.com" >> /etc/hosts
echo "$(minikube ip) grafana.example.com" >> /etc/hosts