cantainer ci/ cd with kubernetes
TRANSCRIPT
![Page 1: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/1.jpg)
鄭毓融23 October 2017
CI/CD with Kubernetes
![Page 2: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/2.jpg)
AgendaIntroduction of Continuous Integration and Continuous Deployment/Delivery
- What is CI/CD?- Run CI/CD with Kubernetes?
Setup Jenkins with Kubernetes- Setup minikube & jenkins- Add kubernetes in jenkins- Test
Summary
2
![Page 3: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/3.jpg)
Introduction of Continuous Integration and Continuous Delivery (CI/CD)
What is CI/CD and Why need that?
![Page 4: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/4.jpg)
Continuous Integration -
「 持續整合 」 目的在儘快讓新功能的程式碼整合到現存的基礎程式庫 (codebase) 中來進行測試 。
Continuous Deploy -
「 持續部署 」 的目的就是要讓軟體可以快速自動部署到不同的環境 , 至於有多少環境需要部署則會根據不同公司的持續交付管線 (pipeline) 的設計而定。
Continuous Delivery -
「 持續交付 」 是將新的特性儘快交付到最終使用者 (end-user) 的手中 。
簡單來說就是盡量減少手動人力,將一些日常工作交給自動化工具。例如:環境建置、單元測試、日誌紀錄、產品部署。
What is CI/CD?
引用自:山姆鍋對持續整合、持續部署、持續交付的定義DevOps:持續整合&持續交付(Docker、CircleCI、AWS)
![Page 5: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/5.jpg)
CI/CD 流程範例
引用自: 安德魯的部落格 - 架構師觀點:你需要什麼樣的CI/CD?
![Page 6: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/6.jpg)
Run CI/CD with Kubernetes
引用自: Achieving CI/CD with Kubernetes
Jenkins 透過 Kubernetes plugin 操作 kubernetes cluster 建立 pod (slaves) 來執行 CI/CD 任務。
Pod 上使用 jenkins/jnlp-slave image,啟動 jnlp java slave 程式,連接 jenkins master。
當完成 CI/CD 任務後,該 pod 自動從 kubernetes cluster 中刪除,釋放資源。
![Page 7: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/7.jpg)
Setup Jenkins with Kubernetes
Use kubernetes-plugin in jenkins
![Page 8: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/8.jpg)
Setup Environment (Minikube)
Host Machine
Virtual Machine (Minikube)
Docker Container (Jenkins Master)
Kubernetes Pod (Jenkins Slave)Kubernetes Pod (Jenkins Slave)
Kubernetes Pod (Jenkins Slave)Kubernetes Pod (Jenkins Slave)
![Page 9: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/9.jpg)
Install minikuberoot@ycheng:/home/ycheng# curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-ubuntu16.04 > /usr/local/bin/docker-machine-driver-kvmroot@ycheng:/home/ycheng# curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.22.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
root@ycheng:/home/ycheng# curl -O "https://storage.googleapis.com/kubernetes-release/release/v1.7.8/bin/linux/amd64/kubectl"root@ycheng:/home/ycheng# chmod +x kubectl && sudo mv kubectl /usr/local/bin/
root@ycheng:/home/ycheng# minikube start --vm-driver=kvmStarting local Kubernetes v1.7.5 cluster...Starting VM...Getting VM IP address...Moving files into cluster...Setting up certs...Connecting to cluster...Setting up kubeconfig...Starting cluster components...Kubectl is now configured to use the cluster.
![Page 10: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/10.jpg)
Run jenkins dockerroot@ycheng:/home/ycheng# minikube ssh _ _ _ _ ( ) ( ) ___ ___ (_) ___ (_)| |/') _ _ | |_ __ /' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ pwd/home/docker$ mkdir /home/docker/jenkins_home$ chmod 777 /home/docker/jenkins_home$ mkdir /home/docker/jenkins_volume$ chmod 777 /home/docker/jenkins_volume$ docker create --name jenkins-k8s jenkins:2.60.3Unable to find image 'jenkins:2.60.3' locally2.60.3: Pulling from library/jenkins3e17c6eae66c: Pull complete ….Status: Downloaded newer image for jenkins:2.60.36f8aef4da1a9ba669e7630ef5deac86c7e15d992ba9a592ff8dca251c4c2c611
![Page 11: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/11.jpg)
Run jenkins docker$ docker run -d --volumes-from jenkins-k8s -p 8080:8080 -p 50000:50000 -v /home/docker/jenkins_home:/var/jenkins_home jenkins:2.60.39107e83bc474e7160fda33c9a52888228ece1e6ad6dd810fca3ac36493b14311$ docker logs 9107e83bc474e7160fda33c9a52888228ece1e6ad6dd810fca3ac36493b14311Running from: /usr/share/jenkins/jenkins.warwebroot: EnvVars.masterEnvVars.get("JENKINS_HOME")….Jenkins initial setup is required. An admin user has been created and a password generated.Please use the following password to proceed to installation:
2e058590dded40e5b3d7996246cf3be2
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
***************************************************************************************************************************************************************************************….--> setting agent port for jnlp--> setting agent port for jnlp... done
![Page 12: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/12.jpg)
Enter jenkins web console
![Page 13: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/13.jpg)
Install suggested plugins
![Page 14: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/14.jpg)
Install suggested plugins
![Page 15: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/15.jpg)
Create admin user
![Page 16: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/16.jpg)
Start using jenkins
![Page 17: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/17.jpg)
Jenkins web UI
![Page 18: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/18.jpg)
Add kubernetes-plugin
![Page 19: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/19.jpg)
Add kubernetes-plugin
![Page 20: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/20.jpg)
Add kubernetes-plugin
![Page 21: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/21.jpg)
Add kubernetes-plugin
![Page 22: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/22.jpg)
Config kubernetes in jenkins
![Page 23: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/23.jpg)
Add kubernetes in jenkins (minikube)
![Page 24: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/24.jpg)
Add kubernetes in jenkins (minikube)root@ycheng:/home/ycheng# cat /root/.kube/config apiVersion: v1clusters:- cluster: certificate-authority: /root/.minikube/ca.crt server: https://192.168.42.102:8443 name: minikubecontexts:- context: cluster: minikube user: minikube name: minikubecurrent-context: minikubekind: Configpreferences: {}users:- name: minikube user: client-certificate: /root/.minikube/apiserver.crt client-key: /root/.minikube/apiserver.key
![Page 25: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/25.jpg)
Add kubernetes in jenkins (minikube)root@ycheng:/home/ycheng# cat /root/.minikube/ca.crt-----BEGIN CERTIFICATE-----MIIC5zCCAc+gAwIBAgIBATANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwptaW5pa3ViZUNBMB4XDTE3MTAxNjA3NDkyNVoXDTI3MTAxNDA3NDkyNVowFTETMBEGA1UEAxMKbWluaWt1YmVDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKv7Yum+t342V8/gJw//sv77Gr/WguJ+0JrQISAIQF4Z+ABitbQ9nX0yoZLSTg80qIcyHDclGF1sQt7BDnfH+UtiCvDrEdMMAqwcYtKGdMW3El7uU6tisnjkwg3ZDflv+7y1l7TZUMyc+ByWql2wm7h+D3b1f1IRPnevGBPKkTK1HYmIowe5nPzOXnHKU+1zSGmtwW6yBswE+xz/Y42YCu2qUNnkPKmVYeQCF8fH4SJRBzczfQ0ZLXmO9y/LtzOqedcVHQv+p0sklG6/ia8Poxn/HdZ3L30hzSGmkwQrwPqL8ty47HTVSx/oC1/jssYMN9mfCFwWinNjNKV7s2RtMekCAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgKkMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCUqJ8skMD5rZ50+h1IMCyek40eCEiwMW3EPqdiEtgr3oxzdurqfoph2mA9mPyvG9sFmDLAxlXi+bWYXOmKd2I0I6wcejk0hSAEdVhLO925vXWMzVuOLiet0lHfOGL+zlTPANq858T6GhVC0WKeK/2moxgOTxHq/oTcpNmfXZHDKMvfmlxcWTwao8uewveZ3QJLaFOFnVWRNqgY/OhFRDW/Mpa4+vNf6r9QX5AUfFGY/0/03MSw+eohaKZsWbjxAPzwhvYw0lb7nRlJusjfn9lGWCI8b7W75UsPjnK6WOMe+7LXRuHIfGRiCBzg8n29bvefS05lsFEf8ZC2X76CyxAF-----END CERTIFICATE-----
![Page 26: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/26.jpg)
Add kubernetes in jenkins (minikube)root@ycheng:~# openssl pkcs12 -export -out ~/.minikube/minikube.pfx -inkey ~/.minikube/apiserver.key -in ~/.minikube/apiserver.crt -certfile ~/.minikube/ca.crt -passout pass:secret
root@ycheng:~# cp -afpR ~/.minikube/minikube.pfx ~root@ycheng:~# ls -l ./minikube.pfx -rw-r--r-- 1 root root 3293 10月 17 14:41 ./minikube.pfx
![Page 27: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/27.jpg)
Add kubernetes in jenkins (minikube)
![Page 28: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/28.jpg)
Add kubernetes in jenkins (minikube)
![Page 29: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/29.jpg)
Add kubernetes in jenkins (minikube)
![Page 30: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/30.jpg)
Add kubernetes in jenkins (minikube)
![Page 31: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/31.jpg)
Create a project
![Page 32: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/32.jpg)
Config project label
![Page 33: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/33.jpg)
Add shell command to test
![Page 34: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/34.jpg)
Run the project
![Page 35: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/35.jpg)
Run the project
![Page 36: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/36.jpg)
Run the project
![Page 37: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/37.jpg)
Run the project
![Page 38: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/38.jpg)
Run the project
![Page 39: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/39.jpg)
Check output
![Page 40: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/40.jpg)
Check outputroot@ycheng:~# minikube ssh _ _ _ _ ( ) ( ) ___ ___ (_) ___ (_)| |/') _ _ | |_ __ /' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ ls -l ./jenkins_volume/total 4-rw-r--r-- 1 10000 10000 48 Oct 17 09:14 output$ cat ./jenkins_volume/output Tue Oct 17 09:14:39 UTC 2017free-job-test-done
![Page 41: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/41.jpg)
Add another kubernetes cluster (2+1)
Host Machine
Virtual Machine (Minikube)
Docker Container (Jenkins Master)
Virtual Machine (Kubernetes node1 - master)
Virtual Machine (Kubernetes node2 - minion)
Virtual Machine (Kubernetes node3 - minion)
![Page 42: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/42.jpg)
kubernetes cluster 2+1root@ycheng:~# virsh list Id Name State---------------------------------------------------- 33 minikube running 34 kubernetes_node1 running 35 kubernetes_node2 running 36 kubernetes_node3 running
root@node1:~# kubectl get node -o wideNAME STATUS AGE VERSION EXTERNAL-IP OS-IMAGE KERNEL-VERSIONnode1 Ready,master 161d v1.6.2 <none> Ubuntu 16.04.2 LTS 4.4.0-62-genericnode2 Ready 161d v1.6.2 <none> Ubuntu 16.04.2 LTS 4.4.0-62-genericnode3 Ready 161d v1.6.2 <none> Ubuntu 16.04.2 LTS 4.4.0-62-generic
root@node1:~# kubectl create ns jenkinsnamespace "jenkins" created
root@node1:~# showmount -e 192.168.2.254Export list for 192.168.2.254:/root/jenkins_output *
![Page 43: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/43.jpg)
Test script and data on NFS serverroot@ycheng:~/jenkins_output# ls -ltotal 4drwxrwxrwx 3 ycheng ycheng 4096 10月 19 17:36 iostat_analyzer_for_jenkins
root@ycheng:~/jenkins_output# ls -l ./iostat_analyzer_for_jenkins/total 40-rwxrwxr-x 1 ycheng ycheng 527 10月 19 17:19 combine_iostat_files.sh-rwxrwxrwx 1 ycheng ycheng 13542 10月 19 17:19 iostat_analysis_io_req.sh-rwxrwxr-x 1 ycheng ycheng 10079 10月 19 11:15 split_by_day.shdrwxrwxrwx 2 ycheng ycheng 4096 10月 19 17:38 rawdata
![Page 44: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/44.jpg)
Config kubernetes cluster
![Page 45: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/45.jpg)
Config kubernetes cluster
![Page 46: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/46.jpg)
Config kubernetes cluster
![Page 47: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/47.jpg)
Create pipeline job
![Page 48: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/48.jpg)
Write pipeline script
![Page 49: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/49.jpg)
Run pipeline job
![Page 50: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/50.jpg)
pipeline stage
![Page 51: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/51.jpg)
pipeline stage
![Page 52: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/52.jpg)
pipeline stage
![Page 53: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/53.jpg)
Terminal output
![Page 54: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/54.jpg)
Terminal output
![Page 55: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/55.jpg)
Summary
![Page 56: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/56.jpg)
Summary
Continuous IntegrationContinuous DeployContinuous DeliveryCI/CD with Kubernetes
Other CI/CD Tools :- Travis CI- Circle CI- Drone.io- gitlab- & more...
![Page 57: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/57.jpg)
References
https://samkuo.me/post/2013/10/continuous-integration-deployment-delivery/http://blog.amowu.com/2015/04/devops-continuous-integration-delivery-docker-circleci-aws-beanstalk.htmlhttp://columns.chicken-house.net/2017/08/05/what-cicd-do-you-need/https://docs.docker.com/samples/library/jenkins/https://travis-ci.org/http://try.drone.io/https://dzone.com/articles/achieving-cicd-with-kubernetes
![Page 58: Cantainer CI/ CD with Kubernetes](https://reader033.vdocuments.pub/reader033/viewer/2022050806/5a6479907f8b9a40568b475f/html5/thumbnails/58.jpg)
www.inwinstack.com
Thank You!迎 棧 科 技 股 份 有 限 公 司