Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Kubernetes Controller for Pull Request Based Environment

4,950 views

Published on

Kubernetes Controller which looks for all the Pull Requests on your repository and deploy Pull Request base branch automatically.

Published in: Engineering
  • These are one of the best companies for review articles. High quality with cheap rates. ⇒⇒⇒WRITE-MY-PAPER.net ⇐⇐⇐ I highly recommend it :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! I can recommend a site that has helped me. It's called ⇒ www.HelpWriting.net ⇐ They helped me for writing my quality research paper.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ♥♥♥ http://bit.ly/39sFWPG ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ♥♥♥ http://bit.ly/39sFWPG ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Kubernetes Controller for Pull Request Based Environment

  1. 1. k8s Controller for Pull Request based Environment
  2. 2. Vishal Banthia SET, Microservices Platform
  3. 3. It means whenever a developer creates a new Pull Request to their microservice, it will be automatically deployed in development environment. What is Pull Request Based Environment?
  4. 4. Simply, it’s great for development, debugging and testing. How it is useful?
  5. 5. Simply, it’s great for development, debugging and testing. If your branch is deployed in cluster and can talk with other services then its really helpful for debugging, development and end to end testing. How it is useful?
  6. 6. How it is useful? ... In microservices architecture, services depend on other services and as it grows dependency graph gets more complicated. It is responsibility of upstream developers to keep their master branch stable so that downstream service development does not halt.
  7. 7. Simple Microservices Architecture Example (BookInfo) Product Page Review Service Detail Service Rating Service
  8. 8. Simple Microservices Architecture Example (BookInfo) Product Page (frontend) Review Service Detail Service Rating Service frontend
  9. 9. Simple Microservices Architecture Example (BookInfo) Product Page (frontend) Review Service Detail Service Rating Service backend (microservices)
  10. 10. ProductPage
  11. 11. ProductPage Detail Service
  12. 12. ProductPage Detail Service Review Service
  13. 13. ProductPage Detail Service Review Service Rating Service
  14. 14. Kubernetes Deployment Product Page Review Service Detail Service Rating Service
  15. 15. # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: rating spec: template: containers: - name: rating image: rating:v1 Kubernetes Deployment (Rating) Product Page Review Service Detail Service Rating Service # service.yaml apiVersion: v1 kind: Service metadata: name: rating spec: ports: - name: TCP port: 80 targetPort: 8080 Rating Service is available at: rating.default.svc.cluster.local
  16. 16. # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: review spec: template: containers: - name: review image: review:v1 env: RATING_URL: rating.default.svc.cluster.local Kubernetes Deployment (Review) Product Page Review Service Detail Service Rating Service # service.yaml apiVersion: v1 kind: Service metadata: name: review spec: ports: - name: TCP port: 80 targetPort: 8080 Review Service is available at: review.default.svc.cluster.local
  17. 17. # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: product-page spec: template: containers: - name: product-page image: product-page:v1 env: REVIEW_URL: review.default.svc.cluster.local DETAIL_URL: detail.default.svc.cluster.local Kubernetes Deployment (ProductPage) Product Page Review Service Detail Service Rating Service # service.yaml apiVersion: v1 kind: Service metadata: name: product-page spec: ports: - name: TCP port: 80 targetPort: 8080 type: LoadBalancer Review Service is available at: product-page.example.com
  18. 18. apiVersion: apps/v1 kind: Deployment metadata: name: product-page spec: template: containers: - name: product-page image: product-page:v1 env: REVIEW_URL: review.default.svc.cluster.local DETAIL_URL: detail.default.svc.cluster.local Kubernetes Deployment (ProductPage) Product Page Review Service Detail Service Rating Service ● Although ProductPage does not have any direct dependency on Rating service but it depends on it. ● If Rating Service breaks, ProductPage might also break.
  19. 19. apiVersion: apps/v1 kind: Deployment metadata: name: product-page spec: template: containers: - name: product-page image: product-page:v1 env: REVIEW_URL: review.default.svc.cluster.local DETAIL_URL: detail.default.svc.cluster.local Kubernetes Deployment (ProductPage) Product Page Review Service Detail Service Rating Service ● Although ProductPage does not have any direct dependency on Rating service but it depends on it. ● If Rating Service breaks, ProductPage might also break. So, it is responsibility of RatingService owners to keep default branch of ratingService tested, so that downstream service development does not halt.
  20. 20. How to make sure Rating Service is stable?
  21. 21. End to End Testing!
  22. 22. ● Manually ● Automated
  23. 23. But, you first need an environment to test your feature branch
  24. 24. But, you first need an environment to test your feature branch https://product-page-{feature}.example.com
  25. 25. Development Workflow Product Page Review Service Detail Service Rating Service
  26. 26. Workflow Product Page Review Service Detail Service Rating Service New Feature Requirement: 6-star-rating
  27. 27. Workflow Product Page Review Service Detail Service Rating Service 6-star-rating (pr-222) rating-222.default.svc.cluster.local
  28. 28. Workflow Product Page Review Service Detail Service Rating Service 6-star-rating (pr-222) rating-222.default.svc.cluster.local 6-star-rating (pr-333) review-333.default.svc.cluster.local
  29. 29. Workflow Product Page Review Service Detail Service Rating Service 6-star-rating (pr-222) rating-222.default.svc.cluster.local 6-star-rating (pr-333) review-333.default.svc.cluster.local 6-star-rating (pr-500) product-page-500.example.com
  30. 30. Workflow Product Page Review Service Detail Service Rating Service 6-star-rating (pr-222) rating-222.default.svc.cluster.local 6-star-rating (pr-333) review-333.default.svc.cluster.local 6-star-rating (pr-333) product-page-500.example.com
  31. 31. k8s Pull Request Replication Controller
  32. 32. Current State -> Desired State Kubernetes Controller Philosophy
  33. 33. Current State -> Desired State Kubernetes Controller Philosophy for { desired := getDesiredState() current := getCurentState() makeChanges(desired, current) }
  34. 34. Desired State There should be a Deployment and a Service for all Pull Requests.
  35. 35. Usage (Rating Service) apiVersion: apps/v1 kind: Deployment metadata: name: rating annotation: pr-rc.alpha.mercari.com/repository: https://github.com/example/rating-service spec: template: containers: - name: rating image: rating:v1 ● Developer needs to add an annotation to let controller know which repository to look.
  36. 36. Pull Request Replication Controller ... func (c *Controller) Run(ctx context.Context) { for { c.RunOnce(ctx) select { case <-time.After(60 * time.Second): } } }
  37. 37. RunOnce() kubernetes API Server
  38. 38. RunOnce() kubernetes API Server GetDeployments("pr-rc.alpha.mercari.com/repository")
  39. 39. RunOnce() kubernetes API Server ListPrs("https://github.com/example/rating-service") (desired state)
  40. 40. RunOnce() kubernetes API Server GetDeploymentsForLabel("pr-rc-repository") (current state)
  41. 41. RunOnce() kubernetes API Server for deploy := range diff(desired - current) { // New Pull Request CreateDuplicateDeployment(deplo y) }
  42. 42. RunOnce() kubernetes API Server for deploy := range diff(current - desired) { // Closed Pull Request DeleteDuplicateDeployment(deplo y) }
  43. 43. How to change environment variables?
  44. 44. .pr-rc.yaml (ProductPage) func CreateDuplicateDeployment(deploy v1.Deployment) { // Get .pr-rc.yaml file for branch prRCYaml := github.GetPrRCYaml() // Override environmnet variable for duplicate deployment duplicateDeploy := mergeDeploy(deploy, prRCYaml) // Create Duplicate Deployment clientset.AppsV1().Deployments().Create(duplicateDeplo y) } # .pr-rc.yaml apiVersion: apps/v1 kind: Deployment spec: replicas: 1 template: spec: containers: - name: product-page image: product-page:pr-{PR_NUM}-{COMM_REF} env: - name: "REVIEW_URL" value: "review- 123.default.svc.cluster.local"
  45. 45. Future Work ● Use CRDs to manage desired state instead of pull requests, so that developers do not need to create pull request of downstream repository ● Allow QA to create complicated environment through UI
  46. 46. References which can help in writing controllers ● https://www.youtube.com/watch?v=_BuqPMlXfpE ● https://engineering.bitnami.com/articles/kubewatch-an-example-of-kubernetes-custom- controller.html ● https://borismattijssen.github.io/articles/kubernetes-informers-controllers-reectors-stores ● https://github.com/kubernetes/sample-controller ● https://github.com/kubernetes/community/blob/master/contributors/devel/controllers.m ● https://github.com/kubernetes/client-go/tree/master/tools/cache

×