1. Answers
  2. Deploy Jenkins JNLP Slave Docker Image on Kubernetes

How do I deploy the jenkins/jnlp-slave:latest Docker image on Kubernetes using Pulumi?

In this guide, we will deploy the jenkins/jnlp-slave:latest Docker image on a Kubernetes cluster using Pulumi and TypeScript. We will define a Kubernetes Deployment and Service to manage the Jenkins slave pods.

Key Points:

  • We will create a Kubernetes Deployment to run the Jenkins JNLP slave pods.
  • We will expose the pods using a Kubernetes Service.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Define the namespace
const namespace = new k8s.core.v1.Namespace("jenkins-slave-ns", {
    metadata: { name: "jenkins-slave" },
});

// Define the Deployment
const deployment = new k8s.apps.v1.Deployment("jenkins-slave-deployment", {
    metadata: {
        namespace: namespace.metadata.name,
        name: "jenkins-slave",
    },
    spec: {
        replicas: 2,
        selector: {
            matchLabels: { app: "jenkins-slave" },
        },
        template: {
            metadata: {
                labels: { app: "jenkins-slave" },
            },
            spec: {
                containers: [{
                    name: "jenkins-slave",
                    image: "jenkins/jnlp-slave:latest",
                    ports: [{ containerPort: 8080 }],
                }],
            },
        },
    },
});

// Define the Service
const service = new k8s.core.v1.Service("jenkins-slave-service", {
    metadata: {
        namespace: namespace.metadata.name,
        name: "jenkins-slave",
    },
    spec: {
        selector: { app: "jenkins-slave" },
        ports: [{ port: 80, targetPort: 8080 }],
    },
});

// Export the service URL
export const serviceUrl = pulumi.interpolate`http://${service.metadata.name}.${namespace.metadata.name}.svc.cluster.local`;

Summary:

In this guide, we have successfully deployed the jenkins/jnlp-slave:latest Docker image on a Kubernetes cluster using Pulumi and TypeScript. We defined a Kubernetes Deployment to manage the Jenkins slave pods and a Service to expose them.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up