From df4a3c6c28bbdea144d455d3f79b1bed70566f4c Mon Sep 17 00:00:00 2001 From: Heba Elayoty Date: Thu, 13 Apr 2023 17:45:06 -0700 Subject: [PATCH 1/3] Update the helm chart Signed-off-by: Heba Elayoty --- .../decisions/0004-documentation.md | 2 +- .../{helmexample => helm-deploy}/.helmignore | 0 .../{helmexample => helm-deploy}/Chart.yaml | 2 +- .../{helmexample => helm-deploy}/README.md | 18 +++- .../templates/NOTES.txt | 16 +--- .../templates/_helpers.tpl | 21 +++-- samples/helm-deploy/templates/deployment.yaml | 46 ++++++++++ samples/helm-deploy/templates/rbac.yaml | 12 +++ samples/helm-deploy/templates/service.yaml | 15 +++ .../helm-deploy/templates/serviceaccount.yaml | 5 + samples/helm-deploy/values.yaml | 31 +++++++ samples/helmexample/templates/deployment.yaml | 57 ------------ samples/helmexample/templates/hpa.yaml | 28 ------ samples/helmexample/templates/ingress.yaml | 61 ------------ samples/helmexample/templates/service.yaml | 15 --- .../helmexample/templates/serviceaccount.yaml | 12 --- .../templates/tests/test-connection.yaml | 15 --- samples/helmexample/values.yaml | 92 ------------------- 18 files changed, 140 insertions(+), 308 deletions(-) rename samples/{helmexample => helm-deploy}/.helmignore (100%) rename samples/{helmexample => helm-deploy}/Chart.yaml (98%) rename samples/{helmexample => helm-deploy}/README.md (92%) rename samples/{helmexample => helm-deploy}/templates/NOTES.txt (62%) rename samples/{helmexample => helm-deploy}/templates/_helpers.tpl (71%) create mode 100644 samples/helm-deploy/templates/deployment.yaml create mode 100644 samples/helm-deploy/templates/rbac.yaml create mode 100644 samples/helm-deploy/templates/service.yaml create mode 100644 samples/helm-deploy/templates/serviceaccount.yaml create mode 100644 samples/helm-deploy/values.yaml delete mode 100644 samples/helmexample/templates/deployment.yaml delete mode 100644 samples/helmexample/templates/hpa.yaml delete mode 100644 samples/helmexample/templates/ingress.yaml delete mode 100644 samples/helmexample/templates/service.yaml delete mode 100644 samples/helmexample/templates/serviceaccount.yaml delete mode 100644 samples/helmexample/templates/tests/test-connection.yaml delete mode 100644 samples/helmexample/values.yaml diff --git a/docs/architecture/decisions/0004-documentation.md b/docs/architecture/decisions/0004-documentation.md index ba0e7fef1..624ee71ec 100644 --- a/docs/architecture/decisions/0004-documentation.md +++ b/docs/architecture/decisions/0004-documentation.md @@ -110,7 +110,7 @@ following implementation of this ADR proposal: ┃ ┣ carbon-aware-webapi.md ┃ ┗ carbon-aware-cli.md ┣ samples/ - ┃ ┣ helmexample/ + ┃ ┣ helm-deploy/ ┃ ┃ ┗ README.md ┃ ┗ python-proxy-server/ ┃ ┗ README.md diff --git a/samples/helmexample/.helmignore b/samples/helm-deploy/.helmignore similarity index 100% rename from samples/helmexample/.helmignore rename to samples/helm-deploy/.helmignore diff --git a/samples/helmexample/Chart.yaml b/samples/helm-deploy/Chart.yaml similarity index 98% rename from samples/helmexample/Chart.yaml rename to samples/helm-deploy/Chart.yaml index 837354aa5..3e29ada40 100644 --- a/samples/helmexample/Chart.yaml +++ b/samples/helm-deploy/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -name: helmexample +name: carbon-aware-sdk description: A Helm chart for Kubernetes # A chart can be either an 'application' or a 'library' chart. diff --git a/samples/helmexample/README.md b/samples/helm-deploy/README.md similarity index 92% rename from samples/helmexample/README.md rename to samples/helm-deploy/README.md index 189c2ed4d..b426a574b 100644 --- a/samples/helmexample/README.md +++ b/samples/helm-deploy/README.md @@ -132,7 +132,7 @@ and going to credentials. To install your helm chart, you should run ```bash -helm install / +helm install carbon-aware ./samples/helm-deploy/ ``` (If you run into an error, see the [troubleshooting](#troubleshooting) section. @@ -145,10 +145,18 @@ for your to copy and paste to deploy the chart. We've replicated below for quick reference (you will need to fill in `nameOverride` and `fullNameOverride`): ```bash -export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=,app.kubernetes.io/instance=" -o jsonpath="{.items[0].metadata.name}") -export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") -echo "Visit http://127.0.0.1:8080 to use your application" -kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT +NAME: carbon-aware +LAST DEPLOYED: Thu Apr 13 17:39:51 2023 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +TEST SUITE: None +NOTES: +1. Get the application URL by running these commands: + export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=carbon-aware-sdk,app.kubernetes.io/instance=carbon-aware" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT ``` If the deployment works properly, you should be able to visit the link they diff --git a/samples/helmexample/templates/NOTES.txt b/samples/helm-deploy/templates/NOTES.txt similarity index 62% rename from samples/helmexample/templates/NOTES.txt rename to samples/helm-deploy/templates/NOTES.txt index ed54c0885..9f0624b9a 100644 --- a/samples/helmexample/templates/NOTES.txt +++ b/samples/helm-deploy/templates/NOTES.txt @@ -1,21 +1,15 @@ 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 "helmexample.fullname" . }}) +{{- if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "carbon-aware-sdk.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 "helmexample.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helmexample.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "carbon-aware-sdk.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "carbon-aware-sdk.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 "helmexample.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "carbon-aware-sdk.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 diff --git a/samples/helmexample/templates/_helpers.tpl b/samples/helm-deploy/templates/_helpers.tpl similarity index 71% rename from samples/helmexample/templates/_helpers.tpl rename to samples/helm-deploy/templates/_helpers.tpl index 9437334f2..0d142ca77 100644 --- a/samples/helmexample/templates/_helpers.tpl +++ b/samples/helm-deploy/templates/_helpers.tpl @@ -1,7 +1,7 @@ {{/* Expand the name of the chart. */}} -{{- define "helmexample.name" -}} +{{- define "carbon-aware-sdk.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} @@ -10,7 +10,7 @@ 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 "helmexample.fullname" -}} +{{- define "carbon-aware-sdk.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "helmexample.chart" -}} +{{- define "carbon-aware-sdk.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} -{{- define "helmexample.labels" -}} -helm.sh/chart: {{ include "helmexample.chart" . }} -{{ include "helmexample.selectorLabels" . }} +{{- define "carbon-aware-sdk.labels" -}} +helm.sh/chart: {{ include "carbon-aware-sdk.chart" . }} +{{ include "carbon-aware-sdk.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -45,17 +45,18 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels */}} -{{- define "helmexample.selectorLabels" -}} -app.kubernetes.io/name: {{ include "helmexample.name" . }} +{{- define "carbon-aware-sdk.selectorLabels" -}} +app.kubernetes.io/name: {{ include "carbon-aware-sdk.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} +name: carbon-aware-sdk {{- end }} {{/* Create the name of the service account to use */}} -{{- define "helmexample.serviceAccountName" -}} +{{- define "carbon-aware-sdk.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} -{{- default (include "helmexample.fullname" .) .Values.serviceAccount.name }} +{{- default (include "carbon-aware-sdk.fullname" .) .Values.serviceAccount.name }} {{- else }} {{- default "default" .Values.serviceAccount.name }} {{- end }} diff --git a/samples/helm-deploy/templates/deployment.yaml b/samples/helm-deploy/templates/deployment.yaml new file mode 100644 index 000000000..1dd4d77c6 --- /dev/null +++ b/samples/helm-deploy/templates/deployment.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "carbon-aware-sdk.fullname" . }} + namespace: {{ .Values.namespace }} + labels: + {{- include "carbon-aware-sdk.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "carbon-aware-sdk.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "carbon-aware-sdk.selectorLabels" . | nindent 8 }} + spec: + serviceAccountName: {{ .Values.rbac.serviceAccountName }} + containers: + - name: {{ .Values.image.name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sh + - -c + - cd /app && sed "s/username/{{ .Values.image.auth.username }}/" -i appsettings.json && sed "s/password/{{ .Values.image.auth.password }}/" -i appsettings.json && dotnet CarbonAware.WebApi.dll + ports: + - name: api-server-port + containerPort: 7031 + + {{- 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/samples/helm-deploy/templates/rbac.yaml b/samples/helm-deploy/templates/rbac.yaml new file mode 100644 index 000000000..6d160e496 --- /dev/null +++ b/samples/helm-deploy/templates/rbac.yaml @@ -0,0 +1,12 @@ +apiVersion: "rbac.authorization.k8s.io/v1" +kind: ClusterRoleBinding +metadata: + name: {{ .Values.rbac.clusterRoleName }} +subjects: + - kind: ServiceAccount + name: {{ .Values.rbac.serviceAccountName }} + namespace: {{ .Values.namespace }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ .Values.rbac.roleRef }} diff --git a/samples/helm-deploy/templates/service.yaml b/samples/helm-deploy/templates/service.yaml new file mode 100644 index 000000000..fdb338c1a --- /dev/null +++ b/samples/helm-deploy/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: carbon-aware-sdk + namespace: {{ .Values.namespace }} + labels: + {{- include "carbon-aware-sdk.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: api-server-port + protocol: TCP + selector: + {{- include "carbon-aware-sdk.selectorLabels" . | nindent 4 }} diff --git a/samples/helm-deploy/templates/serviceaccount.yaml b/samples/helm-deploy/templates/serviceaccount.yaml new file mode 100644 index 000000000..644c1475a --- /dev/null +++ b/samples/helm-deploy/templates/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ .Values.rbac.serviceAccountName }} + namespace: {{ .Values.namespace }} diff --git a/samples/helm-deploy/values.yaml b/samples/helm-deploy/values.yaml new file mode 100644 index 000000000..39cfbad87 --- /dev/null +++ b/samples/helm-deploy/values.yaml @@ -0,0 +1,31 @@ +# Default values for carbon-aware-sdk. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 +namespace: kube-system + +image: + name: carbon-aware-sdk + repository: ghcr.io/green-software-foundation/carbon-aware-sdk + pullPolicy: IfNotPresent + tag: "0.1.0" + auth: + username: username + password: password + +service: + type: ClusterIP + port: 80 + +rbac: + clusterRoleName: carbon-aware-binding + serviceAccountName: carbon-aware-sa + roleRef: cluster-admin + +nameOverride: "" +fullnameOverride: "" +podAnnotations: {} +nodeSelector: {} +tolerations: [] +affinity: {} diff --git a/samples/helmexample/templates/deployment.yaml b/samples/helmexample/templates/deployment.yaml deleted file mode 100644 index 6cd0aef70..000000000 --- a/samples/helmexample/templates/deployment.yaml +++ /dev/null @@ -1,57 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "helmexample.fullname" . }} - labels: - {{- include "helmexample.labels" . | nindent 4 }} -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "helmexample.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "helmexample.selectorLabels" . | nindent 8 }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ include "helmexample.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: 80 - protocol: TCP - livenessProbe: - {{ .Values.monitorConfig.liveness | toYaml | indent 12 | trim }} - readinessProbe: - {{ .Values.monitorConfig.readiness | toYaml | indent 12 | trim }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- 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/samples/helmexample/templates/hpa.yaml b/samples/helmexample/templates/hpa.yaml deleted file mode 100644 index 7ccf2b6d2..000000000 --- a/samples/helmexample/templates/hpa.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2beta1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ include "helmexample.fullname" . }} - labels: - {{- include "helmexample.labels" . | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ include "helmexample.fullname" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: - {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} - {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} -{{- end }} diff --git a/samples/helmexample/templates/ingress.yaml b/samples/helmexample/templates/ingress.yaml deleted file mode 100644 index 95ed7ec83..000000000 --- a/samples/helmexample/templates/ingress.yaml +++ /dev/null @@ -1,61 +0,0 @@ -{{- if .Values.ingress.enabled -}} -{{- $fullName := include "helmexample.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 "helmexample.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/samples/helmexample/templates/service.yaml b/samples/helmexample/templates/service.yaml deleted file mode 100644 index 3a637319e..000000000 --- a/samples/helmexample/templates/service.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "helmexample.fullname" . }} - labels: - {{- include "helmexample.labels" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "helmexample.selectorLabels" . | nindent 4 }} diff --git a/samples/helmexample/templates/serviceaccount.yaml b/samples/helmexample/templates/serviceaccount.yaml deleted file mode 100644 index edb759fb1..000000000 --- a/samples/helmexample/templates/serviceaccount.yaml +++ /dev/null @@ -1,12 +0,0 @@ -{{- if .Values.serviceAccount.create -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "helmexample.serviceAccountName" . }} - labels: - {{- include "helmexample.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -{{- end }} diff --git a/samples/helmexample/templates/tests/test-connection.yaml b/samples/helmexample/templates/tests/test-connection.yaml deleted file mode 100644 index d34f26fb0..000000000 --- a/samples/helmexample/templates/tests/test-connection.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "helmexample.fullname" . }}-test-connection" - labels: - {{- include "helmexample.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test -spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "helmexample.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never diff --git a/samples/helmexample/values.yaml b/samples/helmexample/values.yaml deleted file mode 100644 index 877485e7d..000000000 --- a/samples/helmexample/values.yaml +++ /dev/null @@ -1,92 +0,0 @@ -# Default values for helmexample. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: - repository: carbonawaretoyacr.azurecr.io/ca_0504 - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "latest" - -imagePullSecrets: [] -nameOverride: "helm-example" -fullnameOverride: "helm-chart-example" - -serviceAccount: - # Specifies whether a service account should be created - create: 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: "helmexample" - -podAnnotations: {} - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - 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 - -monitorConfig: - liveness: - httpGet: - path: "/health" - port: "http" - readiness: - httpGet: - path: "/health" - port: "http" - -resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - # limits: - # cpu: 100m - # memory: 128Mi - # requests: - # cpu: 100m - # memory: 128Mi - -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - -nodeSelector: {} - -tolerations: [] - -affinity: {} From 2d0201906dd68f176ad02f0b7e0525644f3c4612 Mon Sep 17 00:00:00 2001 From: Heba Elayoty <31887807+helayoty@users.noreply.github.com> Date: Fri, 16 Jun 2023 19:56:28 +0000 Subject: [PATCH 2/3] Code review comments Signed-off-by: Heba Elayoty <31887807+helayoty@users.noreply.github.com> --- samples/helm-deploy/templates/rbac.yaml | 12 ------------ samples/helm-deploy/values.yaml | 8 ++------ 2 files changed, 2 insertions(+), 18 deletions(-) delete mode 100644 samples/helm-deploy/templates/rbac.yaml diff --git a/samples/helm-deploy/templates/rbac.yaml b/samples/helm-deploy/templates/rbac.yaml deleted file mode 100644 index 6d160e496..000000000 --- a/samples/helm-deploy/templates/rbac.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: "rbac.authorization.k8s.io/v1" -kind: ClusterRoleBinding -metadata: - name: {{ .Values.rbac.clusterRoleName }} -subjects: - - kind: ServiceAccount - name: {{ .Values.rbac.serviceAccountName }} - namespace: {{ .Values.namespace }} -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: {{ .Values.rbac.roleRef }} diff --git a/samples/helm-deploy/values.yaml b/samples/helm-deploy/values.yaml index 39cfbad87..6842ae56a 100644 --- a/samples/helm-deploy/values.yaml +++ b/samples/helm-deploy/values.yaml @@ -3,13 +3,13 @@ # Declare variables to be passed into your templates. replicaCount: 1 -namespace: kube-system +namespace: default image: name: carbon-aware-sdk repository: ghcr.io/green-software-foundation/carbon-aware-sdk pullPolicy: IfNotPresent - tag: "0.1.0" + tag: "latest" auth: username: username password: password @@ -18,10 +18,6 @@ service: type: ClusterIP port: 80 -rbac: - clusterRoleName: carbon-aware-binding - serviceAccountName: carbon-aware-sa - roleRef: cluster-admin nameOverride: "" fullnameOverride: "" From aa0936e372391dc3f61e9cad51af11c148d2af35 Mon Sep 17 00:00:00 2001 From: Heba Elayoty <31887807+helayoty@users.noreply.github.com> Date: Fri, 16 Jun 2023 20:14:15 +0000 Subject: [PATCH 3/3] Update readme Signed-off-by: Heba Elayoty <31887807+helayoty@users.noreply.github.com> --- samples/helm-deploy/README.md | 113 +++--------------- samples/helm-deploy/templates/deployment.yaml | 1 - 2 files changed, 18 insertions(+), 96 deletions(-) diff --git a/samples/helm-deploy/README.md b/samples/helm-deploy/README.md index b426a574b..cbdbf9eaa 100644 --- a/samples/helm-deploy/README.md +++ b/samples/helm-deploy/README.md @@ -1,58 +1,35 @@ -# How-To: Deploy to AKS using Helm +# How-To: Deploy to Kubernetes using Helm ## Setup Dev Environment (optional) -The easiest way to setup your environment is to use a VSCode dev container. -Suggested setup is with the latest `debian` OS with `az CLI` and `kubectl-helm` -packages enabled. +The easiest way to setup your environment is to install [Kind](https://kind.sigs.k8s.io/) or [Minikube](https://minikube.sigs.k8s.io/docs/start/). It is also valid to setup a cloud provider kubernetes cluster (i.e. AKS, EKS, GKE, ...) -## Setup Resource Group in Azure - -1. Create a new Kubernetes service following the default settings -1. Create a container registry -1. Create a key vault - -## Push an image to the container registry +## Push an image to the Docker registry The following steps illustrates how to push a webservice image in order to be -deployed in AKS using ACR (Azure Container Registry). - -1. Build a `published` image using for instancee the following - [Dockerfile](https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows#create-the-dockerfile) - - ```sh - docker build -t myapp:v1 . - ``` +deployed in Kubernetes clsuter. -1. Login into ACR using the username and password credentials that are needed in - order to push. See Access Keys section of the ACR Portal. +1. Build an image using the following + [Dockerfile](.../../../../src/CarbonAware.WebApi/src/Dockerfile) ```sh - docker login .azurecr.io + cd + docker build -t /myapp:v1 . ``` -1. Tag the image following ACR tagging scheme +1. Login into docker using the username and password credentials that are needed in + order to push. ```sh - docker tag myapp .azurecr.io/myapp:v1 + docker login ``` -1. Push to ACR +1. Push to Docker registry ```sh - docker push .azurecr.io/myapp:v1 + docker push /myapp:v1 ``` -After these steps, using Azure's Portal ACR resource an image should be -available under repositories following the naming convention mentioned above. - -### Give cluster access to ACR - -To attach the ACR to the cluster so that the image can be accessed, run - -```bash -az aks update -n -g --attach-acr -``` ## Create a new Helm chart (optional) @@ -78,7 +55,7 @@ In `Chart.yaml`, we won't need to make any changes but make note of the chart In `values.yaml`, we need to change a couple fields. In the `image` section, you will need to set -- The `repository` field to be `/` +- The `repository` field to be `` - The `pullPolicy` field to be `IfNotPresent` (pulls a new image if not present) or `Always` (pulls a new image every time). - The `tag` field if you need a particuar tag version @@ -94,38 +71,6 @@ In the `monitorConfig` section, you will need to adjust the `liveness` and `readiness` that the helm chart will ping to ensure the sdk is ready. As a default, you should set the path to `/health`. -## Connecting to AKS from Helm - -To connect to AKS you need to be logged into the azure. Run `az login` and -follow the prompts to get access to your azure subscriptions. - -To set the right subscription for the service, run: - -```bash -az account set --subscription -``` - -To give credentials for the resource group to the kubernetes service, run: - -```bash -az aks get-credentials --resource-group --name -``` - -With these two commands, helm should be setup to access AKS and be able to -deploy on it. With the current setup, Helm is not directly accessing the ACR to -pull the image, put instead is going through the cluster (which is why we gave -the cluster authorized access to the ACR in the earlier section). If you do need -helm to access your ACR for any reason, you will need to register it and login -with the following - -```bash -helm registry login \ - --username \ - --password -``` - -The neccessary credentials can be found by opening your ACR in the Azure portal -and going to credentials. ### Installing your helm chart @@ -176,32 +121,17 @@ that means that helm cannot connect to kubernetes. Helm connects to kuberentes either via the $KUBECONFIG env variable, or (if it's not set) looks for the default location kubectl files are location (`~/.kube/config`). This may occur the first time to try connecting the helm chart or if you clear the -files/variables. To fix, follow the cli commands in the -[connecting to AKS](#connecting-to-aks-from-helm) section and that should -automatically generate the proper config files. +files/variables. ### Error installing the helm chart -If you get -`Error: INSTALLATION FAILED: cannot re-use a name that is still in use` when you +If you get `Error: INSTALLATION FAILED: cannot re-use a name that is still in use` when you tried to install the helm chart, it means there is still an instance of that chart installed. If you started this instance, you can simply skip the install step and continue. If you're unsure that it's the right installation, or you've made changes, first run `helm uninstall `. Once it's uninstalled, you can redo the helm install step. -### Error pulling image - -If there is an issue pulling the image from ACR, the pod will deploy but will -fail to start. If you check the status of the pod (using the kubectl commands -below in the azure portal) you will see the `ImagePullBackOff` status and a note -that the pod has not started. This may be for a couple reasons: - -1. The cluster isn't authorized to access the ACR registry. Ensure you've run - [this command](#give-cluster-access-to-acr). -2. The image reference in helm is incorrect. Review the Values.yaml - [section](#valuesyaml) to ensure you've got the right reference in the - image repository field. ### Error deploying the helm chart @@ -225,15 +155,8 @@ can actual spin up correctly. ## References -Helm 3: [docs](https://helm.sh/docs/), +- Helm 3: [docs](https://helm.sh/docs/), [image docs](https://helm.sh/docs/chart_best_practices/pods/#images) -MS Docs: -[Creating an ingress controller in AKS](https://docs.microsoft.com/en-us/azure/aks/ingress-basic?tabs=azure-cli), -[Authenticate with ACR from AKS](https://docs.microsoft.com/en-us/azure/aks/cluster-container-registry-integration?tabs=azure-cli#access-with-kubernetes-secret) - -Github Issue: -[Deploying a container from ACR to AKS](https://github.com/MicrosoftDocs/azure-docs/issues/33430) - -ContainIQ: +- ContainIQ: [Troubleshooting ImagePullBackOff Error](https://www.containiq.com/post/kubernetes-imagepullbackoff) diff --git a/samples/helm-deploy/templates/deployment.yaml b/samples/helm-deploy/templates/deployment.yaml index 1dd4d77c6..8a202550d 100644 --- a/samples/helm-deploy/templates/deployment.yaml +++ b/samples/helm-deploy/templates/deployment.yaml @@ -19,7 +19,6 @@ spec: labels: {{- include "carbon-aware-sdk.selectorLabels" . | nindent 8 }} spec: - serviceAccountName: {{ .Values.rbac.serviceAccountName }} containers: - name: {{ .Values.image.name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"