csc603ngo CloudLab profile and launch an experiment from the k8-cdci branch.
1
2
3
$ cd
$ bash /local/repository/launch_network.sh
$ kubectl get nodes
1
$ bash /local/repository/launch_jenkins.sh
spec.replicas: 1spec.containers: jenkins/jenkins:lts spec.containers.ports: http-port:8000 and jnlp-port:50000Service is an abstraction that defines a logical set of Pods and a policy by which to access them.selector.
1
$ kubectl get nodes -o wide
Grab one of the values of INTERNAL-IP, open a browser and go to INTERNAL-IP:30000
To get the initialAdminPassword, you can run the following command on the head node:
1
$ kubectl exec $(kubectl get pods -n jenkins | grep jenkins | awk '{print $1}') -n jenkins -- cat /var/jenkins_home/secrets/initialAdminPassword
kubectl exec allows users to run a bash command directly inside the specified pod.$(kubectl get pods -n jenkins | grep jenkins | awk '{print $1}') is a sequence of pipe commands: $(kubectl get pods -n jenkins get all pods| grep jenkins parses the line containing the jenkins pod names| awk '{print $1}') gets the first column, which is the pod ID only.Continue.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
## Configure Jenkins
- Click on `Install selected plugins`
:::{image} ../fig/csc603/07-kubernetes/05.png
:alt: Install selected plugins for Kubernetes
:class: bg-primary mb-1
:height: 500px
:align: center
:::
- You can either try to create the first admin user or Skip and continue
as admin.
:::{image} ../fig/csc603/07-kubernetes/06.png
:alt: Setup admin user
:class: bg-primary mb-1
:height: 500px
:align: center
:::
- Click `Save and Finish`,
:::{image} ../fig/csc603/07-kubernetes/07.png
:alt: Accept instance configuration
:class: bg-primary mb-1
:height: 500px
:align: center
:::
- Click `Start using Jenkins`
:::{image} ../fig/csc603/07-kubernetes/08.png
:alt: Start using Jenkins
:class: bg-primary mb-1
:height: 500px
:align: center
:::
- This is the Jenkins Dashboard
:::{image} ../fig/csc603/07-kubernetes/09.png
:alt: Jenkins Dashboard
:class: bg-primary mb-1
:height: 500px
:align: center
:::
- Explore the Jenkins Dashboard and figure out how to install two additional plugins:
- Kubernetes
- SSH Agent
:::{image} ../fig/csc603/07-kubernetes/jenkins-extra-agents.png
:alt: Installing additional Kubernetes and SSH Agent plugins
:class: bg-primary mb-1
:height: 200px
:align: center
:::
- On the CloudLab head node, run `ssh-keygen` (do not enter any password when asked).
- Run `cat .ssh/id_rsa.pub >> .ssh/authorized_keys`
- Run `cat ~/.ssh/id_rsa` and copy the displayed text, including the starting
and ending dashes without any extra spaces.
- On Jenkins Dashboard, go to `Manage Jenkins`/`Manage Credentials`.
- Click on `Jenkins` under `Stores scoped to Jenkins`, then `Global credentials (unrestricted)`.
- Click on `Add Credentials`.
- Fill in the boxes as follows:
- `Kind`: SSH Username with private name
- `Scope`: Global (Jenkins, nodes, items, all child items, etc)
- `ID`: cloudlab
- `Username`: Enter your CloudLab login username here.
- `Private Key`: Check `Enter directly`, click `Add`, then paster the previously
copied private key to this box.
- Click `Create`.
- On Jenkins Dashboard, go to `Manage Jenkins`/`Manage Nodes and Clouds`.
- Click on the gear icon for `Built-In Node`
- Fill in the boxes as follows:
- `Number of executors`: 1
- `Labels`: deploy
- `Usage`: Only build jobs with label expressions matching this node
- On Jenkins Dashboard, go to `Manage Jenkins`/`Manage Nodes and Clouds`/`Configure Clouds`.
- Select `Kubernetes` from `Add a new cloud` dropbox.
- Click on `Kubernetes Cloud Details`.
- Fill in the boxes as follows:
- `Kubernetes Name`: kubernetes
- `Kubernetes URL`: Information of the `Kubernetes control plane` gotten from
running `kubectl cluster-info` on the CloudLab head node.
- Check `Direction Connection` box.
- Click `Test Connection` to confirm connection.
- Continue on the `Configure Clouds` from the previous slide.
- Click `Pod Templates` then `Add Pod Template` then `Pod Template details`
- Fill in the boxes as follows:
- `Name`: agent-template
- `Namespace`: jenkins
- `Usage`: Only build jobs with label expressions matching this node
- **Do not add container yet**
- Click on `Add Volume`:
- Select `Host Path Volume`
- Enter `/var/run/docker.sock` for both `Host path` and `Mount path`.
- *This is to enable the building and pushing of Docker images*.
In the scope of `Pod Template`
- Click `Add Container`
- Fill in the boxes as follows:
- `Container Template Name`: golang
- `Docker image`: golang
- Click `Add Container`
- Fill in the boxes as follows:
- `Container Template Name`: gcc
- `Docker image`: gcc:latest
- Click `Add Container`
- `Container Template Name`: docker
- `Docker image`: docker
- Click `Add Environment Variable` for the `docker` container template
- Prior to this, go to `hub.docker.com` and login to your Docker Hub account.
- Go to Account Settings
- Go to `Security`.
- Click on `New Access Token`.
- Enter a short description for this token, allow `Access permission` to
be `Read, Write, Delete`, and then click `Generate`.
- Store this key some where safe.
- First environment variable:
- `Key`: DOCKER_TOKEN
- `Value`: the access token copied from before.
- Second environment variable:
- `Key`: DOCKER_REGISTRY
- `Value`: YOUR_DOCKERHUB_USERNAME/go_server
- Third environment variable:
- `Key`: DOCKER_USER
- `Value`: YOUR_DOCKERHUB_USERNAME
>
- Click `Apply` and then `Save`.
Create a new repository called hello_kube with contents copied from the instructor’s hello repo’s hello_kube branch
Jenkins, create a New Item of type Pipeline and name it hello_kube, click OK.Build Triggers and check GitHub hook trigger for GITScm polling.Pipeline select Pipeline script from SCM.SCM appears, select Git and provide the Repository URL for your hello_kube repo.Branch to build, change */master to */main.Script Path, enter Jenkinsfile. Jenkinsfile in the hello_kube branch.Apply.Click Save.
go_app on your hello repository (from the hands-on in the Jenkins’ eposide).go_app branch should have the same contents as https://github.com/CSC468-WCU/hello/tree/go_appwebhook for the go_app to point to the Jenkins server in the previous slide.main.go: The Go file that serves as the web server (the application to be deployed).main_test.go: The Go file that serves as the test file (part of the CD process).Jenkinsfile: Setup the pipeline for Jenkins to build, test, and push and deploy (if test is passed) the Go app. registry (line 4) to change to YOUR_DOCKERHUB_USERNAME/go_server.registry (line 5) to change to YOUR_DOCKERHUB_USERNAME.registry (line 73, 74, 75): lngo to your CloudLab username.Dockerfile: The Docker image that will package the web server.deployment.yml and service.yml: K8 configuration files.New Item, and create a new Pipelinenamed go_server.Build Triggers tab, select GitHub hook trigger for GITScm polling,Pipeline tab, select the followings: Definition: Pipeline script from SCM (this will open new options)SCM: GitBranch Specifier: go_app Save Build Now to activate the first buildOpen a new browser tab and visit the IP address of head at port 32000 to see the running server
main.go in go_app to introduce and error.main.go and also main_test.go so that the build and test can pass.```