Deploying Jenkins on Kubernetes
We will walk you through deploying Jenkins on a Kubernetes cluster using a dedicated namespace, NodePort service, and a single deployment.
Create a Namespace for Jenkins
kubectl create namespace jenkins
This creates a namespace named jenkins to isolate Jenkins resources from other applications in our cluster.
Create a NodePort Service
We will use the imperative approach, and then save it to a manifest file for some changes.
kubectl create service nodeport jenkins-service -n jenkins --tcp 8080:8080 \
--dry-run=client -o yaml > jenkins-service.yaml
Final service object
Recommended by LinkedIn
apiVersion: v1
kind: Service
metadata:
labels:
app: jenkins
name: jenkins-service
namespace: jenkins
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
nodePort: 30008
selector:
app: jenkins
type: NodePort
selector: Labels to select pods for exposing the service. Here, pods with the label app: jenkins will be included
Create a Jenkins Deployment
Like with the service, we will use the imperative approach and save it to a file.
kubectl create deployment jenkins-deployment -n jenkins --replica=1 \
--image=jenkins/jenkins --port 8080 --dry-run=client -o yaml > jenkins-deployment.yaml
Final deployment object
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: jenkins
name: jenkins-deployment
namespace: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
strategy: {}
template:
metadata:
labels:
app: jenkins
spec:
containers:
- image: jenkins/jenkins
name: jenkins
ports:
- containerPort: 8080
selector: Labels to identify pods managed by our deployment. labels: Labels for the pod template (app: jenkins).