Skip to main content

Continuous integration with Jenkins

Jenkins deployment on Kubernetes

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set kubernetes-ts-jenkins
cd pulumi-examples/kubernetes-ts-jenkins

This example deploys a container running the Jenkins continuous integration system onto a running Kubernetes cluster using Pulumi and @pulumi/kubernetes.

Note: The code in this repo assumes you are deploying to a cluster that supports the LoadBalancer service type. This includes most cloud providers as well as Docker for Mac Edge w/ Kubernetes.

Prerequisites#

  1. Install Pulumi
  2. Configure Kubernetes
  3. Install Node.js

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Create configuration keys for the root username and password for the Jenkins instance we are about to create:

    Terminal window
    pulumi config set username <your desired username>
    pulumi config set password <your desired password> --secret
  3. Set the minikube values. MetalLB is required for LoadBalancer services on minikube. You will either need to enable it yourself with minikube addons enable metallb or set enableMetalLB to true:

    Terminal window
    pulumi config set isMinikube true # set to false if you are not using minikube
    pulumi config set enableMetalLB true
  4. Install dependencies:

    Terminal window
    npm install
  5. Deploy the stack:

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack kubernetes-ts-jenkins-dev created
    + └─ jenkins:jenkins:Instance dev created
    + ├─ kubernetes:core:Secret dev-secret created
    + ├─ kubernetes:core:Service dev-service created
    + ├─ kubernetes:core:PersistentVolumeClaim dev-pvc created
    + └─ kubernetes:apps:Deployment dev-deploy created
    Outputs:
    externalIp: "35.184.131.21"
    Resources:
    + 6 created
    Duration: 1m58s
  6. The deployment is complete! Use pulumi stack output externalIp to see the IP of the Service that we just deployed:

    Terminal window
    pulumi stack output externalIp
    35.184.131.21

    The Jenkins instance we just deployed is reachable through port 80 of the external IP address. You can now visit http://35.184.131.21/login in a web browser to begin the first-install flow for your new Jenkins instance. You can use the username and password that you saved in your Pulumi config to log in to your new Jenkins instance.

    Note: If you are deploying to a cluster that does not support type: "LoadBalancer", and deployed the example using type: "ClusterIP" instead, run kubectl port-forward svc/jenkins 8080:80 to forward the cluster port to the local machine and access the service via localhost:8080.

Cleaning up#

Once you’re finished experimenting, you can destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.