-
Notifications
You must be signed in to change notification settings - Fork 2
/
part2.yml
77 lines (52 loc) · 5.5 KB
/
part2.yml
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
parts:
- name: Part 2
intro: In this part we will Setup Jenkins, and setup an automated pipeline to build, push and deploy our custom appliction.
steps:
- cap: Start up the Kubernetes cluster with Minikube.
com: minikube stop; minikube start --memory 8000 --cpus 2
- cap: Before we do anything, let's make sure the private registry deployment we've setup in the previous part is available.
com: kubectl rollout status deployment/registry
- cap: Let's build the Kubectl Docker image we'll use in our Jenkins Pipeline.
com: docker build -t 127.0.0.1:30400/k8s-kubectl:latest -f applications/k8s-kubectl/Dockerfile applications/k8s-kubectl
- cap: Once again we'll need to set up the Socat Registry proxy container to push images, so let's build it. Feel free to skip this step in case the socat-registry image already exists from Part 1 (to check, run `docker images` in a separate terminal).
com: docker build -t socat-registry -f applications/socat/Dockerfile applications/socat
- cap: Run the proxy container from the image.
com: docker stop socat-registry; docker rm socat-registry; docker run -d -e "REG_IP=`minikube ip`" -e "REG_PORT=30400" --name socat-registry -p 30400:5000 socat-registry; sleep 10
- cap: With our proxy container up and running, we can now push our Jenkins image to the local repository.
com: docker push 127.0.0.1:30400/k8s-kubectl:latest
- cap: The proxy’s work is done, so you can go ahead and stop it.
com: docker stop socat-registry
- cap: Let's build the Jenkins Docker image we'll use in our Kubernetes cluster.
com: docker build -t 127.0.0.1:30400/jenkins:latest -f applications/jenkins/Dockerfile applications/jenkins
- cap: Once again we'll need to set up the Socat Registry proxy container to push images, so let's build it. Feel free to skip this step in case the socat-registry image already exists from Part 1 (to check, run `docker images` in a separate terminal).
com: docker build -t socat-registry -f applications/socat/Dockerfile applications/socat
- cap: Run the proxy container from the image.
com: docker stop socat-registry; docker rm socat-registry; docker run -d -e "REG_IP=`minikube ip`" -e "REG_PORT=30400" --name socat-registry -p 30400:5000 socat-registry; sleep 10
- cap: With our proxy container up and running, we can now push our Jenkins image to the local repository.
com: docker push 127.0.0.1:30400/jenkins:latest
- cap: The proxy’s work is done, so you can go ahead and stop it.
com: docker stop socat-registry
- cap: Deploy Jenkins, which we’ll use to create our automated CI/CD pipeline. It will take the pod a minute or two to roll out.
com: kubectl apply -f manifests/jenkins.yaml; kubectl rollout status deployment/jenkins
- cap: Open the Jenkins UI in a web browser.
com: minikube service jenkins
- cap: Display the Jenkins admin password with the following command, and right-click to copy it. IMPORTANT: BE CAREFUL NOT TO PRESS CTRL-C TO COPY THE PASSWORD AS THIS WILL STOP THE SCRIPT
com: kubectl exec -it `kubectl get pods --selector=app=jenkins --output=jsonpath={.items..metadata.name}` cat /var/jenkins_home/secrets/initialAdminPassword
- cap: Switch back to the Jenkins UI. Paste the Jenkins admin password in the box and click Continue. Click Install suggested plugins. Plugins have actually been pre-downloaded during the Jenkins image build, so this step should finish fairly quickly.
com: echo ''
- cap: Create an admin user and credentials, and click Save and Continue. (Make sure to remember these credentials as you will need them for repeated logins.) On the Instance Configuration page, click Save and Finish. On the next page, click Restart (if it appears to hang for some time on restarting, you may have to refresh the browser window). Login to Jenkins.
com: echo ''
- cap: Before we create a pipeline, we first need to provision the Kubernetes Continuous Deploy plugin with a kubeconfig file that will allow access to our Kubernetes cluster. In Jenkins on the left, click on Credentials, select the Jenkins store, then Global credentials (unrestricted), and Add Credentials on the left menu.
com: echo ''
- cap: The following values must be entered precisely as indicated: for the Kind field select the option `Kubernetes configuration (kubeconfig)`, set the ID as `demo_kubeconfig`, set Kubeconfig to `From a file on the Jenkins master`, and specify the the file path as `/var/jenkins_home/.kube/config`. Click the OK button.
com: echo ''
- cap: We now want to create a new pipeline for use with our Hello-World app. Back on Jenkins home, on the left, click New Item. Enter the item name as "Hello-World Pipeline", select Pipeline, and click OK.
com: echo ''
- cap: Under the Pipeline section at the bottom, change the Definition to be "Pipeline script from SCM".
com: echo ''
- cap: Change the SCM to Git. Change the Repository URL to be the URL of your forked Git repository, such as https://github.com/[GIT USERNAME]/kubernetes-ci-cd. Click Save. On the left, click Build Now to run the new pipeline.
com: echo ''
- cap: After all pipeline stages are colored green as complete, view the Hello-World application.
com: minikube service hello-world
- cap: Push a change to your fork. Run the job again. View the changes.
com: minikube service hello-world