From 05ebe7b677b5a54db492bb3f5e7157c21cd39f92 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 3 Mar 2024 19:25:42 +0300 Subject: [PATCH 01/26] added deploy code for vote and redis --- deploy/redis/deployment.yaml | 24 ++++++++++++++++++++++++ deploy/redis/service.yaml | 18 ++++++++++++++++++ deploy/vote/deployment.yaml | 24 ++++++++++++++++++++++++ deploy/vote/service.yaml | 19 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 deploy/redis/deployment.yaml create mode 100644 deploy/redis/service.yaml create mode 100644 deploy/vote/deployment.yaml create mode 100644 deploy/vote/service.yaml diff --git a/deploy/redis/deployment.yaml b/deploy/redis/deployment.yaml new file mode 100644 index 00000000..e8d1a349 --- /dev/null +++ b/deploy/redis/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + app: redis + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app: redis + strategy: {} + template: + metadata: + creationTimestamp: null + labels: + app: redis + spec: + containers: + - image: redis:alpine + name: redis + resources: {} +status: {} diff --git a/deploy/redis/service.yaml b/deploy/redis/service.yaml new file mode 100644 index 00000000..51ec2144 --- /dev/null +++ b/deploy/redis/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + app: redis + name: redis +spec: + ports: + - name: "6379" + port: 6379 + protocol: TCP + targetPort: 6379 + selector: + app: redis + type: ClusterIP +status: + loadBalancer: {} diff --git a/deploy/vote/deployment.yaml b/deploy/vote/deployment.yaml new file mode 100644 index 00000000..2946c2f5 --- /dev/null +++ b/deploy/vote/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + app: vote + name: vote +spec: + replicas: 2 + selector: + matchLabels: + app: vote + strategy: {} + template: + metadata: + creationTimestamp: null + labels: + app: vote + spec: + containers: + - image: schoolofdevops/vote:v1 + name: vote + resources: {} +status: {} diff --git a/deploy/vote/service.yaml b/deploy/vote/service.yaml new file mode 100644 index 00000000..7da25bf8 --- /dev/null +++ b/deploy/vote/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + app: vote + name: vote +spec: + ports: + - name: "80" + nodePort: 30000 + port: 80 + protocol: TCP + targetPort: 80 + selector: + app: vote + type: NodePort +status: + loadBalancer: {} From 3f1864b3575ae5ccfd0360b4f7ca003d2c5a18c1 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 3 Mar 2024 19:39:03 +0300 Subject: [PATCH 02/26] added README for deploy code --- deploy/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 deploy/README.md diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 00000000..3df55e78 --- /dev/null +++ b/deploy/README.md @@ -0,0 +1 @@ +This is a DEployment Code for Kubernetes From 99b0232c037f0843ee8f31e73e9ef7fbef7d346b Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 3 Mar 2024 19:43:59 +0300 Subject: [PATCH 03/26] updated README --- deploy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/README.md b/deploy/README.md index 3df55e78..24c01ae8 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1 +1,2 @@ This is a DEployment Code for Kubernetes +This code would be used by Flux to deploy to a Kubernetes environment From d79453b408fb67d7653533a4078ccf8966077215 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 3 Mar 2024 20:13:39 +0300 Subject: [PATCH 04/26] added a new label to vote app --- deploy/vote/deployment.yaml | 2 ++ deploy/vote/service.yaml | 1 + 2 files changed, 3 insertions(+) diff --git a/deploy/vote/deployment.yaml b/deploy/vote/deployment.yaml index 2946c2f5..011c6037 100644 --- a/deploy/vote/deployment.yaml +++ b/deploy/vote/deployment.yaml @@ -4,6 +4,7 @@ metadata: creationTimestamp: null labels: app: vote + tier: front name: vote spec: replicas: 2 @@ -16,6 +17,7 @@ spec: creationTimestamp: null labels: app: vote + tier: front spec: containers: - image: schoolofdevops/vote:v1 diff --git a/deploy/vote/service.yaml b/deploy/vote/service.yaml index 7da25bf8..de6bee0d 100644 --- a/deploy/vote/service.yaml +++ b/deploy/vote/service.yaml @@ -4,6 +4,7 @@ metadata: creationTimestamp: null labels: app: vote + tier: front name: vote spec: ports: From 44281269f1fa863b3ad20c270361c6f182bfe42b Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 3 Mar 2024 21:26:42 +0300 Subject: [PATCH 05/26] updating README --- deploy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/README.md b/deploy/README.md index 24c01ae8..e29cc694 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,2 +1,3 @@ This is a DEployment Code for Kubernetes This code would be used by Flux to deploy to a Kubernetes environment +Test before enforcing branching model From 96b7d7a9e52b1656994bb15c5715f410b0f613d4 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 3 Mar 2024 21:52:08 +0300 Subject: [PATCH 06/26] updating README --- deploy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/README.md b/deploy/README.md index e29cc694..49052a86 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -1,3 +1,4 @@ This is a DEployment Code for Kubernetes This code would be used by Flux to deploy to a Kubernetes environment Test before enforcing branching model +Test after enforcing branching model From 4c35610194f428e36806f2848b273a9e6ffe8615 Mon Sep 17 00:00:00 2001 From: Rodgers Biwott <51644799+kiplongu@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:09:10 +0300 Subject: [PATCH 07/26] Update deployment.yaml Added replicas to 4 --- deploy/vote/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/vote/deployment.yaml b/deploy/vote/deployment.yaml index 011c6037..a10f6f84 100644 --- a/deploy/vote/deployment.yaml +++ b/deploy/vote/deployment.yaml @@ -7,7 +7,7 @@ metadata: tier: front name: vote spec: - replicas: 2 + replicas: 4 selector: matchLabels: app: vote From 68c4f7fc6bfc60bf6c5cffdb2778d19898281c50 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Thu, 7 Mar 2024 10:27:56 +0300 Subject: [PATCH 08/26] refactored code with kustomize overlays --- deploy/vote/{ => base}/deployment.yaml | 0 deploy/vote/base/kustomization.yaml | 5 +++++ deploy/vote/{ => base}/service.yaml | 0 deploy/vote/dev/deployment.yaml | 15 +++++++++++++++ deploy/vote/dev/kustomization.yaml | 8 ++++++++ 5 files changed, 28 insertions(+) rename deploy/vote/{ => base}/deployment.yaml (100%) create mode 100644 deploy/vote/base/kustomization.yaml rename deploy/vote/{ => base}/service.yaml (100%) create mode 100644 deploy/vote/dev/deployment.yaml create mode 100644 deploy/vote/dev/kustomization.yaml diff --git a/deploy/vote/deployment.yaml b/deploy/vote/base/deployment.yaml similarity index 100% rename from deploy/vote/deployment.yaml rename to deploy/vote/base/deployment.yaml diff --git a/deploy/vote/base/kustomization.yaml b/deploy/vote/base/kustomization.yaml new file mode 100644 index 00000000..dffc32ff --- /dev/null +++ b/deploy/vote/base/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- deployment.yaml +- service.yaml diff --git a/deploy/vote/service.yaml b/deploy/vote/base/service.yaml similarity index 100% rename from deploy/vote/service.yaml rename to deploy/vote/base/service.yaml diff --git a/deploy/vote/dev/deployment.yaml b/deploy/vote/dev/deployment.yaml new file mode 100644 index 00000000..626f594b --- /dev/null +++ b/deploy/vote/dev/deployment.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + app: vote + name: vote +spec: + minReadySeconds: 20 + replicas: 3 + template: + spec: + containers: + - image: schoolofdevops/vote:v4 + name: vote diff --git a/deploy/vote/dev/kustomization.yaml b/deploy/vote/dev/kustomization.yaml new file mode 100644 index 00000000..f57e642f --- /dev/null +++ b/deploy/vote/dev/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../base + +patchesStrategicMerge: +- deployment.yaml From 60a918eb5ed1bb062da44b8161185316cc0f43d3 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Thu, 7 Mar 2024 11:44:16 +0300 Subject: [PATCH 09/26] added kustomization overlay for staging --- deploy/vote/staging/deployment.yaml | 15 +++++++++++++++ deploy/vote/staging/kustomization.yaml | 8 ++++++++ deploy/vote/staging/service.yaml | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 deploy/vote/staging/deployment.yaml create mode 100644 deploy/vote/staging/kustomization.yaml create mode 100644 deploy/vote/staging/service.yaml diff --git a/deploy/vote/staging/deployment.yaml b/deploy/vote/staging/deployment.yaml new file mode 100644 index 00000000..408d3da6 --- /dev/null +++ b/deploy/vote/staging/deployment.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + app: vote + name: vote +spec: + replicas: 5 + template: + spec: + containers: + - image: schoolofdevops/vote:v3 + name: vote + diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml new file mode 100644 index 00000000..30f8d0c8 --- /dev/null +++ b/deploy/vote/staging/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../base +patchesStrategicMerge: +- deployment.yaml +- service.yaml +namespace: instavote diff --git a/deploy/vote/staging/service.yaml b/deploy/vote/staging/service.yaml new file mode 100644 index 00000000..4f505e7b --- /dev/null +++ b/deploy/vote/staging/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + app: vote + name: vote +spec: + ports: + - name: "80" + port: 80 + targetPort: 80 + nodePort: 30200 + protocol: TCP From e178dab81f6dfd737b1db554987b5eb362e42274 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Thu, 7 Mar 2024 20:20:26 +0300 Subject: [PATCH 10/26] configure image and replicas count --- deploy/vote/staging/kustomization.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml index 30f8d0c8..98306161 100644 --- a/deploy/vote/staging/kustomization.yaml +++ b/deploy/vote/staging/kustomization.yaml @@ -1,8 +1,18 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization + resources: - ../base + patchesStrategicMerge: - deployment.yaml - service.yaml + namespace: instavote + +images: + - name: schoolofdevops/vote + newTag: v4 +replicas: + - name: vote + count: 4 From 41b0a5800ea912ddbf4070606621fbe648b071e7 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Thu, 7 Mar 2024 21:20:45 +0300 Subject: [PATCH 11/26] common labels and annotations --- deploy/vote/staging/kustomization.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml index 98306161..f97c1aff 100644 --- a/deploy/vote/staging/kustomization.yaml +++ b/deploy/vote/staging/kustomization.yaml @@ -16,3 +16,10 @@ images: replicas: - name: vote count: 4 + +commonLabels: + project: instavote + env: staging + +commonAnnotations: + supported-by: "sre@example.com" From bad57cf1fa898c7313354d9995a078902c04ae15 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Thu, 7 Mar 2024 22:15:04 +0300 Subject: [PATCH 12/26] generate configmap from literals --- deploy/vote/staging/deployment.yaml | 4 ++++ deploy/vote/staging/kustomization.yaml | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/deploy/vote/staging/deployment.yaml b/deploy/vote/staging/deployment.yaml index 408d3da6..a9e744bb 100644 --- a/deploy/vote/staging/deployment.yaml +++ b/deploy/vote/staging/deployment.yaml @@ -12,4 +12,8 @@ spec: containers: - image: schoolofdevops/vote:v3 name: vote + envFrom: + - configMapRef: + name: vote + optional: true diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml index f97c1aff..1b7a12f2 100644 --- a/deploy/vote/staging/kustomization.yaml +++ b/deploy/vote/staging/kustomization.yaml @@ -23,3 +23,9 @@ commonLabels: commonAnnotations: supported-by: "sre@example.com" + +configMapGenerator: + - name: vote + literals: + - OPTION_A=STAGING + - OPTION_B=DEV From 6ff1ee93bba56d7860ab6b74b3a7fd66d3ff5755 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Fri, 8 Mar 2024 18:20:07 +0300 Subject: [PATCH 13/26] configured replicas count --- deploy/vote/staging/deployment.yaml | 2 +- deploy/vote/staging/kustomization.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/vote/staging/deployment.yaml b/deploy/vote/staging/deployment.yaml index a9e744bb..516cd8f1 100644 --- a/deploy/vote/staging/deployment.yaml +++ b/deploy/vote/staging/deployment.yaml @@ -6,7 +6,7 @@ metadata: app: vote name: vote spec: - replicas: 5 + replicas: 1 template: spec: containers: diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml index 1b7a12f2..92afbcb0 100644 --- a/deploy/vote/staging/kustomization.yaml +++ b/deploy/vote/staging/kustomization.yaml @@ -15,7 +15,7 @@ images: newTag: v4 replicas: - name: vote - count: 4 + count: 1 commonLabels: project: instavote From e692fd0deef115a1a87876cb58512cbf421dd342 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Fri, 8 Mar 2024 18:26:08 +0300 Subject: [PATCH 14/26] testing rollout on config update --- deploy/vote/staging/kustomization.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml index 92afbcb0..1917fb8a 100644 --- a/deploy/vote/staging/kustomization.yaml +++ b/deploy/vote/staging/kustomization.yaml @@ -27,5 +27,5 @@ commonAnnotations: configMapGenerator: - name: vote literals: - - OPTION_A=STAGING - - OPTION_B=DEV + - OPTION_A=FluxCD + - OPTION_B=ArgoCD From 895bd212d1beb506236cf8321a2784319ebb89c5 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Fri, 8 Mar 2024 19:36:41 +0300 Subject: [PATCH 15/26] add kustomizations for redis --- deploy/dev/kustomization.yaml | 5 +++++ deploy/redis/{ => base}/deployment.yaml | 0 deploy/redis/base/kustomization.yaml | 5 +++++ deploy/redis/{ => base}/service.yaml | 0 deploy/staging/kustomization.yaml | 10 ++++++++++ 5 files changed, 20 insertions(+) create mode 100644 deploy/dev/kustomization.yaml rename deploy/redis/{ => base}/deployment.yaml (100%) create mode 100644 deploy/redis/base/kustomization.yaml rename deploy/redis/{ => base}/service.yaml (100%) create mode 100644 deploy/staging/kustomization.yaml diff --git a/deploy/dev/kustomization.yaml b/deploy/dev/kustomization.yaml new file mode 100644 index 00000000..8a762793 --- /dev/null +++ b/deploy/dev/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../base + diff --git a/deploy/redis/deployment.yaml b/deploy/redis/base/deployment.yaml similarity index 100% rename from deploy/redis/deployment.yaml rename to deploy/redis/base/deployment.yaml diff --git a/deploy/redis/base/kustomization.yaml b/deploy/redis/base/kustomization.yaml new file mode 100644 index 00000000..dffc32ff --- /dev/null +++ b/deploy/redis/base/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- deployment.yaml +- service.yaml diff --git a/deploy/redis/service.yaml b/deploy/redis/base/service.yaml similarity index 100% rename from deploy/redis/service.yaml rename to deploy/redis/base/service.yaml diff --git a/deploy/staging/kustomization.yaml b/deploy/staging/kustomization.yaml new file mode 100644 index 00000000..92a7e0ad --- /dev/null +++ b/deploy/staging/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../base +commonLabels: + project: instavote + env: staging +commonAnnotations: + supported-by: "sre@example.com" +namespace: instavote From f2865acc90fae0237bc8100a329e160f395890f4 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Fri, 8 Mar 2024 20:06:01 +0300 Subject: [PATCH 16/26] updated kustomizations path for redis --- deploy/{ => redis}/dev/kustomization.yaml | 0 deploy/{ => redis}/staging/kustomization.yaml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename deploy/{ => redis}/dev/kustomization.yaml (100%) rename deploy/{ => redis}/staging/kustomization.yaml (100%) diff --git a/deploy/dev/kustomization.yaml b/deploy/redis/dev/kustomization.yaml similarity index 100% rename from deploy/dev/kustomization.yaml rename to deploy/redis/dev/kustomization.yaml diff --git a/deploy/staging/kustomization.yaml b/deploy/redis/staging/kustomization.yaml similarity index 100% rename from deploy/staging/kustomization.yaml rename to deploy/redis/staging/kustomization.yaml From 0944cdd092fc1c8768ed6ac63d36e58471872d10 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sat, 9 Mar 2024 20:49:04 +0300 Subject: [PATCH 17/26] set Memory and CPU resource limits --- deploy/vote/base/deployment.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deploy/vote/base/deployment.yaml b/deploy/vote/base/deployment.yaml index a10f6f84..e4c02360 100644 --- a/deploy/vote/base/deployment.yaml +++ b/deploy/vote/base/deployment.yaml @@ -22,5 +22,11 @@ spec: containers: - image: schoolofdevops/vote:v1 name: vote - resources: {} + resources: + requests: + cpu: "50m" + memory: "100Mi" + limits: + cpu: "50m" + memory: "100Mi" status: {} From c4a25a1201e6b5a5076794ee175ff8d26e09e9fe Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sat, 9 Mar 2024 20:55:59 +0300 Subject: [PATCH 18/26] set Memory and CPU resource limits for redis --- deploy/redis/base/deployment.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deploy/redis/base/deployment.yaml b/deploy/redis/base/deployment.yaml index e8d1a349..68267470 100644 --- a/deploy/redis/base/deployment.yaml +++ b/deploy/redis/base/deployment.yaml @@ -20,5 +20,11 @@ spec: containers: - image: redis:alpine name: redis - resources: {} + resources: + requests: + cpu: "50m" + memory: "100Mi" + limits: + cpu: "50m" + memory: "100Mi" status: {} From 32ee60bc61abbf9df265c8ad9af16b86f6aa6a5e Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sat, 9 Mar 2024 22:59:53 +0300 Subject: [PATCH 19/26] add kustomizations for worker --- deploy/worker/base/deployment.yaml | 24 ++++++++++++++++++++++++ deploy/worker/base/kustomization.yaml | 4 ++++ deploy/worker/staging/kustomization.yaml | 10 ++++++++++ 3 files changed, 38 insertions(+) create mode 100644 deploy/worker/base/deployment.yaml create mode 100644 deploy/worker/base/kustomization.yaml create mode 100644 deploy/worker/staging/kustomization.yaml diff --git a/deploy/worker/base/deployment.yaml b/deploy/worker/base/deployment.yaml new file mode 100644 index 00000000..52e825ed --- /dev/null +++ b/deploy/worker/base/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: worker +spec: + replicas: 1 + selector: + matchLabels: + app: worker + template: + metadata: + labels: + app: worker + spec: + containers: + - name: worker + image: schoolofdevops/worker:latest + resources: + requests: + cpu: "50m" + memory: "100Mi" + limits: + cpu: "50m" + memory: "100Mi" diff --git a/deploy/worker/base/kustomization.yaml b/deploy/worker/base/kustomization.yaml new file mode 100644 index 00000000..42835f53 --- /dev/null +++ b/deploy/worker/base/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- deployment.yaml diff --git a/deploy/worker/staging/kustomization.yaml b/deploy/worker/staging/kustomization.yaml new file mode 100644 index 00000000..92a7e0ad --- /dev/null +++ b/deploy/worker/staging/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../base +commonLabels: + project: instavote + env: staging +commonAnnotations: + supported-by: "sre@example.com" +namespace: instavote From 59aa3582bb9bb1f9bcbd0c015fbfe772c4a95c51 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 10 Mar 2024 09:40:43 +0300 Subject: [PATCH 20/26] add chart for result app --- deploy/charts/result/.helmignore | 23 ++++ deploy/charts/result/Chart.yaml | 24 ++++ deploy/charts/result/templates/NOTES.txt | 22 ++++ deploy/charts/result/templates/_helpers.tpl | 62 +++++++++++ .../charts/result/templates/deployment.yaml | 68 ++++++++++++ deploy/charts/result/templates/hpa.yaml | 32 ++++++ deploy/charts/result/templates/ingress.yaml | 61 +++++++++++ deploy/charts/result/templates/service.yaml | 15 +++ .../result/templates/serviceaccount.yaml | 13 +++ .../templates/tests/test-connection.yaml | 15 +++ deploy/charts/result/values.yaml | 103 ++++++++++++++++++ 11 files changed, 438 insertions(+) create mode 100644 deploy/charts/result/.helmignore create mode 100644 deploy/charts/result/Chart.yaml create mode 100644 deploy/charts/result/templates/NOTES.txt create mode 100644 deploy/charts/result/templates/_helpers.tpl create mode 100644 deploy/charts/result/templates/deployment.yaml create mode 100644 deploy/charts/result/templates/hpa.yaml create mode 100644 deploy/charts/result/templates/ingress.yaml create mode 100644 deploy/charts/result/templates/service.yaml create mode 100644 deploy/charts/result/templates/serviceaccount.yaml create mode 100644 deploy/charts/result/templates/tests/test-connection.yaml create mode 100644 deploy/charts/result/values.yaml diff --git a/deploy/charts/result/.helmignore b/deploy/charts/result/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/deploy/charts/result/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deploy/charts/result/Chart.yaml b/deploy/charts/result/Chart.yaml new file mode 100644 index 00000000..5c7a9491 --- /dev/null +++ b/deploy/charts/result/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: result +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/deploy/charts/result/templates/NOTES.txt b/deploy/charts/result/templates/NOTES.txt new file mode 100644 index 00000000..be100fad --- /dev/null +++ b/deploy/charts/result/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "result.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "result.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "result.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "result.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/deploy/charts/result/templates/_helpers.tpl b/deploy/charts/result/templates/_helpers.tpl new file mode 100644 index 00000000..949b90e3 --- /dev/null +++ b/deploy/charts/result/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "result.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "result.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "result.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "result.labels" -}} +helm.sh/chart: {{ include "result.chart" . }} +{{ include "result.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "result.selectorLabels" -}} +app.kubernetes.io/name: {{ include "result.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "result.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "result.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deploy/charts/result/templates/deployment.yaml b/deploy/charts/result/templates/deployment.yaml new file mode 100644 index 00000000..c128557a --- /dev/null +++ b/deploy/charts/result/templates/deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "result.fullname" . }} + labels: + {{- include "result.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "result.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "result.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "result.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/deploy/charts/result/templates/hpa.yaml b/deploy/charts/result/templates/hpa.yaml new file mode 100644 index 00000000..825db7ad --- /dev/null +++ b/deploy/charts/result/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "result.fullname" . }} + labels: + {{- include "result.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "result.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/deploy/charts/result/templates/ingress.yaml b/deploy/charts/result/templates/ingress.yaml new file mode 100644 index 00000000..a7f3b194 --- /dev/null +++ b/deploy/charts/result/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "result.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "result.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/deploy/charts/result/templates/service.yaml b/deploy/charts/result/templates/service.yaml new file mode 100644 index 00000000..1592e5db --- /dev/null +++ b/deploy/charts/result/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "result.fullname" . }} + labels: + {{- include "result.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "result.selectorLabels" . | nindent 4 }} diff --git a/deploy/charts/result/templates/serviceaccount.yaml b/deploy/charts/result/templates/serviceaccount.yaml new file mode 100644 index 00000000..c9505757 --- /dev/null +++ b/deploy/charts/result/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "result.serviceAccountName" . }} + labels: + {{- include "result.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/deploy/charts/result/templates/tests/test-connection.yaml b/deploy/charts/result/templates/tests/test-connection.yaml new file mode 100644 index 00000000..30ff9f48 --- /dev/null +++ b/deploy/charts/result/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "result.fullname" . }}-test-connection" + labels: + {{- include "result.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "result.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/deploy/charts/result/values.yaml b/deploy/charts/result/values.yaml new file mode 100644 index 00000000..7984e3ca --- /dev/null +++ b/deploy/charts/result/values.yaml @@ -0,0 +1,103 @@ +# Default values for result. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: schoolofdevops/vote-result + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: NodePort + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} From 172859bea9a033ca74cab3569e5f6ef2a1517076 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Sun, 10 Mar 2024 19:46:43 +0300 Subject: [PATCH 21/26] update resource limits for result --- deploy/charts/result/values.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/charts/result/values.yaml b/deploy/charts/result/values.yaml index 7984e3ca..b2b2a40e 100644 --- a/deploy/charts/result/values.yaml +++ b/deploy/charts/result/values.yaml @@ -61,11 +61,11 @@ ingress: resources: limits: - cpu: 100m - memory: 128Mi + cpu: 50m + memory: 100Mi requests: - cpu: 100m - memory: 128Mi + cpu: 50m + memory: 100Mi livenessProbe: httpGet: From b1375acddca7a379a5d076f850ef86f2d8c700f7 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Mon, 11 Mar 2024 22:29:16 +0300 Subject: [PATCH 22/26] Updated resource limits for containers --- deploy/charts/result/values.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/deploy/charts/result/values.yaml b/deploy/charts/result/values.yaml index b2b2a40e..ff2c3a6a 100644 --- a/deploy/charts/result/values.yaml +++ b/deploy/charts/result/values.yaml @@ -60,12 +60,13 @@ ingress: # - chart-example.local resources: - limits: - cpu: 50m - memory: 100Mi - requests: - cpu: 50m - memory: 100Mi + container: + limits: + cpu: 50m + memory: 100Mi + requests: + cpu: 50m + memory: 100Mi livenessProbe: httpGet: From 7cb2c5c8442db9a19515e83f54d3475c444e4af4 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Tue, 12 Mar 2024 11:21:03 +0300 Subject: [PATCH 23/26] added resource limit chart for result app --- deploy/charts/result/values.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/charts/result/values.yaml b/deploy/charts/result/values.yaml index ff2c3a6a..09f89bcd 100644 --- a/deploy/charts/result/values.yaml +++ b/deploy/charts/result/values.yaml @@ -62,11 +62,11 @@ ingress: resources: container: limits: - cpu: 50m - memory: 100Mi + cpu: "50m" + memory: "100Mi" requests: - cpu: 50m - memory: 100Mi + cpu: "50m" + memory: "100Mi" livenessProbe: httpGet: From 857097fb494cdbdd8a8575cbcc8edda2894a8d90 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Tue, 12 Mar 2024 11:31:08 +0300 Subject: [PATCH 24/26] Updated resource limit chart for result app --- deploy/charts/result/values.yaml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/deploy/charts/result/values.yaml b/deploy/charts/result/values.yaml index 09f89bcd..83ac5973 100644 --- a/deploy/charts/result/values.yaml +++ b/deploy/charts/result/values.yaml @@ -60,13 +60,12 @@ ingress: # - chart-example.local resources: - container: - limits: - cpu: "50m" - memory: "100Mi" - requests: - cpu: "50m" - memory: "100Mi" + limits: + cpu: "50m" + memory: "100Mi" + requests: + cpu: "50m" + memory: "100Mi" livenessProbe: httpGet: From 4a3cafc4ce832475d55a6089a53b2a573dd6683d Mon Sep 17 00:00:00 2001 From: kiplongu Date: Wed, 13 Mar 2024 09:28:29 +0300 Subject: [PATCH 25/26] Updated image tag version --- deploy/vote/staging/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/vote/staging/deployment.yaml b/deploy/vote/staging/deployment.yaml index 516cd8f1..c1b0b604 100644 --- a/deploy/vote/staging/deployment.yaml +++ b/deploy/vote/staging/deployment.yaml @@ -10,7 +10,7 @@ spec: template: spec: containers: - - image: schoolofdevops/vote:v3 + - image: schoolofdevops/vote:v4 name: vote envFrom: - configMapRef: From 0e24203eed83fda38848be8e1ee21df949dae9b1 Mon Sep 17 00:00:00 2001 From: kiplongu Date: Wed, 13 Mar 2024 11:26:45 +0300 Subject: [PATCH 26/26] added new tag for the vote app --- deploy/vote/staging/kustomization.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy/vote/staging/kustomization.yaml b/deploy/vote/staging/kustomization.yaml index 1917fb8a..51a6a210 100644 --- a/deploy/vote/staging/kustomization.yaml +++ b/deploy/vote/staging/kustomization.yaml @@ -12,7 +12,8 @@ namespace: instavote images: - name: schoolofdevops/vote - newTag: v4 + newTag: v3 + replicas: - name: vote count: 1