2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
-
Upload
devopsdaysaustin -
Category
Software
-
view
744 -
download
0
Transcript of 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins
![Page 1: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/1.jpg)
CI/CD with Kubernetes
Sandeep Parikh@crcsmnkyHead of Solutions, US EastGoogle Cloud Platform
![Page 2: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/2.jpg)
Why Is This ImportantBulletproof process to go from code to production
Centralized, repeatable building/tagging/pushing
Iterate quickly and reliably
Hands off my kubectl
![Page 3: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/3.jpg)
Continuous Integration
TestCode Commit Push TestBuild
The ideal development flow
![Page 4: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/4.jpg)
Continuous Integration
TestCode Commit Push TestBuild
The ideal development flow
TestD’oh!Code Commit Push Test
Crap!Build
Whoops!
The real development flow
![Page 5: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/5.jpg)
Continuous Delivery
TestBuild Deploy
Testing
Staging
![Page 6: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/6.jpg)
Continuous Deployment
DeployApproveDeliver $$$
![Page 7: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/7.jpg)
Why Continuous?Fail fast
The build broke!
Triage fast
Why did the build break?
Deliver faster
Better software in customers hands!
![Page 8: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/8.jpg)
Tools
![Page 9: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/9.jpg)
Jenkins
![Page 10: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/10.jpg)
Kubernetes Cluster (GKE)
Kubernetes Cluster
Node 1 Node 3Node 2
![Page 11: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/11.jpg)
Kubernetes Cluster (GKE)
Jenkins Leader
Node 1 Node 3Node 2
Jenkins Leader
![Page 12: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/12.jpg)
Kubernetes Cluster (GKE)
Jenkins Service
Node 1 Node 3Node 2
Jenkins Leader
Jenkins Service
![Page 13: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/13.jpg)
Kubernetes Cluster (GKE)
Jenkins Ingress
Node 1 Node 3Node 2
Jenkins Leader
Jenkins Service
Google Cloud Load Balancer
![Page 14: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/14.jpg)
Kubernetes Cluster (GKE)
Jenkins Builders
Node 1 Node 3Node 2
Jenkins Leader
Jenkins Builder
Jenkins Builder
Jenkins Builder
Jenkins Builder
Jenkins Service
Jenkins Builder
Google Cloud Load Balancer
![Page 15: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/15.jpg)
Microservices
![Page 16: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/16.jpg)
Backend
![Page 17: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/17.jpg)
Frontend
![Page 18: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/18.jpg)
Kubernetes Cluster (GKE)
Node 1
Microservices
Node 2
![Page 19: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/19.jpg)
Kubernetes Cluster (GKE)
Node 1
Microservices
Node 2
BackendBackend Backend
![Page 20: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/20.jpg)
Kubernetes Cluster (GKE)
Microservices
Node 2Node 1
Backend
Backend
Service
Backend Backend
Google Cloud Load Balancer
![Page 21: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/21.jpg)
Kubernetes Cluster (GKE)
Microservices
Node 2Node 1
Backend
Frontend Frontend
Backend
Service
Frontend
Backend Backend
Google Cloud Load Balancer
![Page 22: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/22.jpg)
Kubernetes Cluster (GKE)
Microservices
Node 2Node 1
Backend
Frontend Frontend
Backend
Service
Frontend
Frontend
Service
Backend Backend
Google Cloud Load Balancer
![Page 23: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/23.jpg)
Microservices & NamespacesVirtual clusters backed by the same physical cluster
Divide cluster resources by different use cases
Supports quotas for managing resources
Test, Staging, Production, etc.
![Page 24: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/24.jpg)
Pods
Time
Microservices & Rolling Update DeploymentsReplace Replication Controller Deployment A with Replication Controller Deployment B by updating one Pod at a time.
A
B
A
B
AB A
B
A
B
A
B
![Page 25: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/25.jpg)
Rolling Update vs. DeploymentsImperative vs Declarative
Rollback
kubectl edit and kubectl apply
Server-side
...
![Page 26: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/26.jpg)
Workflow
![Page 27: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/27.jpg)
Kubernetes Workflow
CreatePushPackage Expose
![Page 28: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/28.jpg)
Mapping To JenkinsWorkflow plugin, Freestyle doesn’t fit
Define a flexible, extensible, script-based CD pipeline
Groovy for scripting actions
Supports human input/approval
![Page 29: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/29.jpg)
node('docker') { checkout scm // Kubernetes cluster info def cluster = 'gtc' def zone = 'us-central1-f' def project = 'REPLACE_WITH_YOUR_PROJECT_NAME' // Run tests stage 'Go tests' docker.image('golang:1.5.1').inside { sh('go get -d -v') sh('go test') } // Build image with Go binary stage 'Build Docker image' def img = docker.build("gcr.io/${project}/gceme:${env.BUILD_TAG}") sh('gcloud docker -a') img.push()
Jenkinsfile
![Page 30: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/30.jpg)
// Deploy image to cluster in dev namespace stage 'Deploy to QA cluster' docker.image('buildpack-deps:jessie-scm').inside { sh('apt-get update -y ; apt-get install jq') sh('export CLOUDSDK_CORE_DISABLE_PROMPTS=1 ; curl https://sdk.cloud.google.com | bash') sh("/root/google-cloud-sdk/bin/gcloud container clusters get-credentials ${cluster} --zone ${zone}") sh('curl -o /usr/bin/kubectl https://storage.googleapis.com/.../release/v1.0.1/bin/linux/amd64/kubectl ; chmod +x /usr/bin/kubectl') sh("kubectl --namespace=staging rollingupdate gceme-frontend --image=${img.id}") sh("kubectl --namespace=staging rollingupdate gceme-backend --image=${img.id}") sh("echo http://`kubectl --namespace=staging get service/gceme --output=json | jq -r '.status.loadBalancer.ingress[0].ip'`> staging") }
Jenkinsfile
![Page 31: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/31.jpg)
// Deploy to prod if approved stage 'Approve, deploy to prod' def url = readFile('staging').trim() input message: "Does staging at $url look good? ", ok: "Deploy to production" sh('gcloud docker -a') img.push('latest') docker.image('buildpack-deps:jessie-scm').inside { sh('apt-get update -y ; apt-get install jq') sh('export CLOUDSDK_CORE_DISABLE_PROMPTS=1 ; curl https://sdk.cloud.google.com | bash') sh("/root/google-cloud-sdk/bin/gcloud container clusters get-credentials ${cluster} --zone ${zone}") sh('curl -o /usr/bin/kubectl https://storage.googleapis.com/.../release/v1.0.1/bin/linux/amd64/kubectl ; chmod +x /usr/bin/kubectl') sh("kubectl --namespace=production rollingupdate gceme-frontend --image=${img.id}") sh("kubectl --namespace=production rollingupdate gceme-backend --image=${img.id}") sh("echo http://`kubectl --namespace=production get service/gceme --output=json | jq -r '.status.loadBalancer.ingress[0].ip'`") }}
Jenkinsfile
![Page 32: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/32.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production
![Page 33: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/33.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production1
Push1
![Page 34: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/34.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production1 2
Push
Build
1
2
![Page 35: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/35.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production1 2
3
Push
Build
Clone
1
2
3
![Page 36: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/36.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production1 2
3
4
Push
Build
Clone
Stage
1
2
3
4
![Page 37: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/37.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production1 2
3
5
4
Push
Build
Clone
Stage
Approve
1
2
3
4
5
![Page 38: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/38.jpg)
Workflow
Repo
Kubernetes Cluster (GKE)Github
Jenkins
µservice
µservice
Default Staging
Production1 2
3
5
4
Push
Build
Clone
Stage
Approve
Deploy
1
2
3
4
5
6
6
![Page 39: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/39.jpg)
Questions, Comments@crcsmnkyRepo
https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetesUpdates coming (built pre-Jenkins 2.0, which includes Workflow)Changes include Ingress, Deployments, Jenkins+K8S Plugin (auto-spawn builders)Docs
Automated Image Builds with Jenkins, Packer, and KubernetesDistributed Load Testing using KubernetesReal-time data analysis with Kubernetes, Google Cloud Pub/Sub, and BigQuery
Resources
![Page 40: 2016 - Continuously Delivering Microservices in Kubernetes using Jenkins](https://reader036.fdocuments.in/reader036/viewer/2022062316/586fdcb51a28ab18428b65bb/html5/thumbnails/40.jpg)
Join the Google Cloud Platform User Group