Skip to content

Commit fe7658d

Browse files
authored
Updating kubernetes-jenkins for fixes #1717 (#1785)
1 parent 7b7180b commit fe7658d

File tree

3 files changed

+80
-29
lines changed

3 files changed

+80
-29
lines changed

kubernetes-ts-jenkins/README.md

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# Continuous Integration with Jenkins
2+
13
[![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)
24
[![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)
35

4-
# Continuous Integration with Jenkins
5-
66
This example deploys a container running the Jenkins continuous integration system onto a running
77
Kubernetes cluster using Pulumi and `@pulumi/kubernetes`.
88

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

25-
```
26-
$ npm install
21+
```bash
22+
23+
npm install
2724
```
2825

2926
Create a new stack:
3027

31-
```
32-
$ pulumi stack init dev
28+
```bash
29+
pulumi stack init dev
3330
```
3431

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

35+
```bash
36+
pulumi config set username <your desired username>
37+
pulumi config set password <your desired password> --secret
3838
```
39-
$ pulumi config set username <your desired username>
40-
$ pulumi config set password <your desired password> --secret
39+
40+
Setting the minikube values:
41+
>_Note_: [MetalLb](https://metallb.io/) is required for minikube. You will either need to enable it yourself with:
42+
>`minikube addons enable metallb` or set `enableMetalLB` to true.
43+
44+
```bash
45+
pulumi config set isMinikube true #set to false if you are not using minikube
46+
pulumi config set enableMetalLB true
4147
```
4248

4349
Preview the deployment of the application:
4450

45-
```
51+
```bash
4652
$ pulumi preview
4753
Previewing update (dev):
4854
Type Name Plan
@@ -59,7 +65,8 @@ Resources:
5965

6066
Perform the deployment:
6167

62-
```
68+
```bash
69+
6370
$ pulumi up --skip-preview
6471
Updating (dev):
6572
Type Name Status
@@ -81,7 +88,8 @@ Duration: 1m58s
8188

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

84-
```
91+
```bash
92+
8593
$ pulumi stack output externalIp
8694
35.184.131.21
8795
```
@@ -96,7 +104,8 @@ You can use the username and password that you saved in your Pulumi config to lo
96104
97105
When you're ready to be done with Jenkins, you can destroy the instance:
98106

99-
```
107+
```bash
108+
100109
$ pulumi destroy
101110
Do you want to perform this destroy? yes
102111
Destroying (dev):

kubernetes-ts-jenkins/index.ts

+53-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
2-
2+
import * as command from "@pulumi/command";
3+
import * as k8s from "@pulumi/kubernetes";
34
import * as pulumi from "@pulumi/pulumi";
45
import * as jenkins from "./jenkins";
56

67
// Minikube does not implement services of type `LoadBalancer`; require the user to specify if we're
78
// running on minikube, and if so, create only services of type ClusterIP.
89
const config = new pulumi.Config();
10+
let metalLB: command.local.Command | undefined = undefined;
11+
let checkMetalLB: command.local.Command | undefined = undefined;
12+
let metalLBConfig: k8s.core.v1.ConfigMap | undefined = undefined;
13+
914
if (config.require("isMinikube") === "true") {
10-
throw new Error("This example does not yet support minikube");
11-
}
15+
if (config.require("enableMetalLB") === "true") {
16+
// Enable MetalLB in Minikube with wait
17+
metalLB = new command.local.Command("MetalLB", {
18+
create: `minikube addons enable metallb && minikube addons list | grep metallb | grep -q enabled`,
19+
delete: `minikube addons disable metallb`,
20+
}, {
21+
deleteBeforeReplace: true,
22+
});
23+
}
24+
checkMetalLB = new command.local.Command("MetalLB", {
25+
create: `minikube addons list --output json`,
26+
}, { deleteBeforeReplace: true, dependsOn: metalLB ? [metalLB] : [] });
27+
pulumi.jsonParse(checkMetalLB.stdout).apply(json => {
28+
if (json["metallb"]["Status"] !== "enabled") {
29+
throw new Error("This example requires MetalLB to be enabled in minikube, you can enable it by running `minikube addons enable metallb`");
30+
}
31+
});
1232

13-
const instance = new jenkins.Instance({
14-
name: pulumi.getStack(),
15-
credentials: {
16-
username: config.require("username"),
17-
password: config.require("password"),
33+
metalLBConfig = new k8s.core.v1.ConfigMap("metallbConfig", {
34+
metadata: {
35+
namespace: "metallb-system",
36+
name: "config",
37+
annotations: {
38+
"pulumi.com/patchForce": "true",
39+
},
1840
},
19-
resources: {
20-
memory: "512Mi",
21-
cpu: "100m",
41+
data: {
42+
config: `
43+
address-pools:
44+
- name: default
45+
protocol: layer2
46+
addresses:
47+
- 192.168.49.240-192.168.49.250
48+
`,
2249
},
23-
});
50+
}, { deleteBeforeReplace: true, dependsOn: [checkMetalLB] });
51+
}
52+
53+
const instance = new jenkins.Instance({
54+
name: pulumi.getStack(),
55+
credentials: {
56+
username: config.require("username"),
57+
password: config.require("password"),
58+
},
59+
resources: {
60+
memory: "512Mi",
61+
cpu: "100m",
62+
},
63+
}, { dependsOn: metalLBConfig ? [metalLBConfig] : [] });
64+
2465
export const externalIp = instance.externalIp;

kubernetes-ts-jenkins/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"@types/node": "12.20.55"
55
},
66
"dependencies": {
7+
"@pulumi/command": "^1.0.1",
78
"@pulumi/kubernetes": "4.19.0",
89
"@pulumi/pulumi": "3.145.0"
910
}

0 commit comments

Comments
 (0)