Skip to content

Commit

Permalink
Updating kubernetes-jenkins for fixes #1717 (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
rshade authored Jan 13, 2025
1 parent 7b7180b commit fe7658d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 29 deletions.
43 changes: 26 additions & 17 deletions kubernetes-ts-jenkins/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Continuous Integration with Jenkins

[![Deploy this example with Pulumi](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/kubernetes-ts-jenkins/README.md#gh-light-mode-only)
[![Deploy this example with Pulumi](https://get.pulumi.com/new/button-light.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/kubernetes-ts-jenkins/README.md#gh-dark-mode-only)

# Continuous Integration with Jenkins

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

Expand All @@ -14,35 +14,41 @@ Kubernetes](https://www.pulumi.com/docs/intro/cloud-providers/kubernetes/setup/)
> _Note_: The code in this repo assumes you are deploying to a cluster that supports the
> [`LoadBalancer`](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer) service type.
> This includes most cloud providers as well as [Docker for Mac Edge w/
> Kubernetes](https://docs.docker.com/docker-for-mac/kubernetes/). If not (for example if you are targeting `minikube`
> or your own custom Kubernetes cluster), replace `type: "LoadBalancer"` with `type: "ClusterIP"` in `jenkins.ts`. See
> the Kubernetes [Services
> docs](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types) for more
> details.
> Kubernetes](https://docs.docker.com/docker-for-mac/kubernetes/).
Install dependencies:

```
$ npm install
```bash

npm install
```

Create a new stack:

```
$ pulumi stack init dev
```bash
pulumi stack init dev
```

Create configuration keys for the root username and password for the Jenkins instance we are
about to create:

```bash
pulumi config set username <your desired username>
pulumi config set password <your desired password> --secret
```
$ pulumi config set username <your desired username>
$ pulumi config set password <your desired password> --secret

Setting the minikube values:
>_Note_: [MetalLb](https://metallb.io/) is required for minikube. You will either need to enable it yourself with:
>`minikube addons enable metallb` or set `enableMetalLB` to true.
```bash
pulumi config set isMinikube true #set to false if you are not using minikube
pulumi config set enableMetalLB true
```

Preview the deployment of the application:

```
```bash
$ pulumi preview
Previewing update (dev):
Type Name Plan
Expand All @@ -59,7 +65,8 @@ Resources:

Perform the deployment:

```
```bash

$ pulumi up --skip-preview
Updating (dev):
Type Name Status
Expand All @@ -81,7 +88,8 @@ Duration: 1m58s

The deployment is complete! Use `pulumi stack output externalIp` to see the IP of the Service that we just deployed:

```
```bash

$ pulumi stack output externalIp
35.184.131.21
```
Expand All @@ -96,7 +104,8 @@ You can use the username and password that you saved in your Pulumi config to lo
When you're ready to be done with Jenkins, you can destroy the instance:

```
```bash

$ pulumi destroy
Do you want to perform this destroy? yes
Destroying (dev):
Expand Down
65 changes: 53 additions & 12 deletions kubernetes-ts-jenkins/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,65 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as command from "@pulumi/command";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import * as jenkins from "./jenkins";

// Minikube does not implement services of type `LoadBalancer`; require the user to specify if we're
// running on minikube, and if so, create only services of type ClusterIP.
const config = new pulumi.Config();
let metalLB: command.local.Command | undefined = undefined;
let checkMetalLB: command.local.Command | undefined = undefined;
let metalLBConfig: k8s.core.v1.ConfigMap | undefined = undefined;

if (config.require("isMinikube") === "true") {
throw new Error("This example does not yet support minikube");
}
if (config.require("enableMetalLB") === "true") {
// Enable MetalLB in Minikube with wait
metalLB = new command.local.Command("MetalLB", {
create: `minikube addons enable metallb && minikube addons list | grep metallb | grep -q enabled`,
delete: `minikube addons disable metallb`,
}, {
deleteBeforeReplace: true,
});
}
checkMetalLB = new command.local.Command("MetalLB", {
create: `minikube addons list --output json`,
}, { deleteBeforeReplace: true, dependsOn: metalLB ? [metalLB] : [] });
pulumi.jsonParse(checkMetalLB.stdout).apply(json => {
if (json["metallb"]["Status"] !== "enabled") {
throw new Error("This example requires MetalLB to be enabled in minikube, you can enable it by running `minikube addons enable metallb`");
}
});

const instance = new jenkins.Instance({
name: pulumi.getStack(),
credentials: {
username: config.require("username"),
password: config.require("password"),
metalLBConfig = new k8s.core.v1.ConfigMap("metallbConfig", {
metadata: {
namespace: "metallb-system",
name: "config",
annotations: {
"pulumi.com/patchForce": "true",
},
},
resources: {
memory: "512Mi",
cpu: "100m",
data: {
config: `
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.49.240-192.168.49.250
`,
},
});
}, { deleteBeforeReplace: true, dependsOn: [checkMetalLB] });
}

const instance = new jenkins.Instance({
name: pulumi.getStack(),
credentials: {
username: config.require("username"),
password: config.require("password"),
},
resources: {
memory: "512Mi",
cpu: "100m",
},
}, { dependsOn: metalLBConfig ? [metalLBConfig] : [] });

export const externalIp = instance.externalIp;
1 change: 1 addition & 0 deletions kubernetes-ts-jenkins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@types/node": "12.20.55"
},
"dependencies": {
"@pulumi/command": "^1.0.1",
"@pulumi/kubernetes": "4.19.0",
"@pulumi/pulumi": "3.145.0"
}
Expand Down

0 comments on commit fe7658d

Please sign in to comment.