{"id":22173845,"url":"https://github.com/puneethkumarck/canary-microservice-deployment","last_synced_at":"2025-06-25T08:05:38.501Z","repository":{"id":129140254,"uuid":"461339052","full_name":"Puneethkumarck/canary-microservice-deployment","owner":"Puneethkumarck","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-20T13:43:04.000Z","size":553,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-17T22:41:46.755Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Puneethkumarck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-19T23:34:25.000Z","updated_at":"2022-02-19T23:35:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"bad49918-1cf0-4ca5-833c-fd92c0d1d123","html_url":"https://github.com/Puneethkumarck/canary-microservice-deployment","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Puneethkumarck/canary-microservice-deployment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fcanary-microservice-deployment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fcanary-microservice-deployment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fcanary-microservice-deployment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fcanary-microservice-deployment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Puneethkumarck","download_url":"https://codeload.github.com/Puneethkumarck/canary-microservice-deployment/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fcanary-microservice-deployment/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261832632,"owners_count":23216495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T07:35:48.454Z","updated_at":"2025-06-25T08:05:38.480Z","avatar_url":"https://github.com/Puneethkumarck.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Canary Deployments\n\nCanary deployments are a pattern for rolling out releases to a subset of users or servers. The idea is to first deploy the change to a small subset of servers, test it, and then roll the change out to the rest of the servers.\n\nIn our below example you will learn following\n* using the kubernetes labels to define the canary deployments\n* Running multiple version of the application parrallel ,leave it to kubernetes service to load balance between new and old deployments\n* test functionality of the new deployment\n* Gracefully bring-down the old version\n\n\n\u003cb\u003eInitial Status of the application\u003c/b\u003e\n\n![img.png](images/initial.png)\n\n\u003cb\u003eIntermediate Status of the application\u003c/b\u003e\n\n![img_1.png](images/intermediate.png)\n\n\u003cb\u003eFinal status of the application\u003c/b\u003e\n\n![img_2.png](images/final_status.png)\n\nBelow is an small spring boot application which respond with greeting message\n\nwith initial deployment -\u003e Hello from web2.0\n\nwith Final deployment -\u003e Hello from web3.0\n\n### Pre requisite installation\n\n* Java 11\n* maven\n* kubernetes docker for desktop/minikube\n\n\n### Tech\n\n* Java 11\n* Springboot\n* Lombok\n* Maven\n* kubernetes\n* Docker\n    \n\n### Clone \n\n\n### generate spring boot project command-line\n\n```\ncurl https://start.spring.io/starter.tgz -d dependencies=web,lombok -d baseDir=canary-microservice-deployment -d bootVersion=2.6.3 -d javaVersion=11 | tar -xzvf -\n```\n\n### Copy docker file to root directory with name Dockerfile\n\n```\nFROM openjdk:11.0-jdk-slim\nARG JAR_FILE=target/*.jar\nCOPY ${JAR_FILE} app.jar\nENTRYPOINT [\"java\",\"-jar\",\"/app.jar\"]\n```\n\n### Build\n\n```\nmvn clean install\n```\n\n\n```\nBuild docker image \n\ndocker build -t greeting . \n```\n\n![img.png](images/img.png)\n\n\n```\ndocker image ls  // list docker images\n\n```\n![img.png](images/docker_image_ls.png)\n\n\n### Deploy\n\nKubernetes initial Deployment object with 3 replicas , notice labels with app: greeting and type:canary.\n\ncreate kubernetes deployment and service file under k8s directory \n\n```\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: web2.0\n  labels:\n    app: greeting\n    type: canary\nspec:\n  replicas: 3\n  selector:\n    matchLabels:\n      app: greeting\n  template:\n    metadata:\n      labels:\n        app: greeting\n        type: canary\n    spec:\n      containers:\n        - name: greeting\n          image: greeting:latest\n          ports:\n            - containerPort: 8080\n          imagePullPolicy: IfNotPresent\n```\n\nKubernetes service \n\n```\n\napiVersion: v1\nkind: Service\nmetadata:\n  name: greetingservice\nspec:\n  selector:\n    app: greeting\n  ports:\n    - port: 8080\n      targetPort: 8080\n  type: LoadBalancer\n  \n```\n\n```\nkubectl create -f k8s/deployment.yaml\n```\n\n![img.png](images/deployment.png)\n\n```\nkubectl get deployment,svc,po\n```\n\n![img.png](images/deploymentstatus.png)\n### Run\n\n```\nwhile true; do curl http://localhost:8080/; sleep 2; done\n\nYou will see the always spring-boot service will respond with Hello from web2.0 \n```\n\n## Canary deployment\nupdate kubernetes deployment which uses configmap and diff replicas with new deployment name\n\n```\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: web3.0\n  labels:\n    app: greeting\n    type: canary\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: greeting\n  template:\n    metadata:\n      labels:\n        app: greeting\n        type: canary\n    spec:\n      containers:\n        - name: greeting\n          image: greeting:latest\n          imagePullPolicy: IfNotPresent\n          env:\n            - name: greeting.message\n              valueFrom:\n                configMapKeyRef:\n                  name: canary-config\n                  key: greeting.message\n          ports:\n            - containerPort: 8080\n```\n\nCreate the configmap required for the new deployment\n\n```\nkubectl create configmap canary-config --from-literal=greeting.message=\"Hello from web3.0\"\n```\n\n![img.png](images/configmap.png)\n\ncheck the deployment objects to verify config map deployment\n\n```\nkubectl get deployment,svc,po,cm\n```\n![img.png](images/updated deployment status.png)\n\ndeploy updated kubernetes deployment with latest changes as mentioned above \n\n```\nkubectl create -f k8s/deployment-new.yaml\n```\n![img.png](images/new_deployment.png)\n\n![img_1.png](images/new_deployment_status.png)\n\nobserve new deployment appeared with name web3.0 in the above image\n\nNow 25% of the traffic will route to new service deployment, now verify the service response , which will have mixed response from old and new deployment\n\n```\nwhile true; do curl http://localhost:8080/; sleep 2; done\n```\n![img.png](images/curl_after_new_deployment.png)\n\nonce you test and make sure the new changes in the deployment , now scale down the old deployment and make the new deployment 100%. \ncurrently we have an 3 replicas of old deployment and 1 replicas of new deployment\n\n```\nkubectl get deploy --show-labels\n```\n![img.png](images/show_labels.png)\n\n![img.png](images/pod_status.png)\n\nscale down the old deployment to zero instance and scale up the new deployment to 3 with below command\n\n```\nscale deploy web2.0 --replicas=0\nkubectl scale deploy web3.0 --replicas=3\n```\n![img.png](images/new_deployment_scaled.png)\n\nnow test the application , which will respond always with new updated code.\n\n```\nwhile true; do curl http://localhost:8080/; sleep 2; done\n```\n\n![img.png](images/web3response.png)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuneethkumarck%2Fcanary-microservice-deployment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuneethkumarck%2Fcanary-microservice-deployment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuneethkumarck%2Fcanary-microservice-deployment/lists"}