Skip to content

Commit

Permalink
Update the helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>
  • Loading branch information
helayoty committed Apr 14, 2023
1 parent 2db0f30 commit df4a3c6
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 308 deletions.
2 changes: 1 addition & 1 deletion docs/architecture/decisions/0004-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 13 additions & 5 deletions samples/helmexample/README.md → samples/helm-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ and going to credentials.
To install your helm chart, you should run
```bash
helm install <fullNameOverride> <helm-chart-name>/
helm install carbon-aware ./samples/helm-deploy/
```
(If you run into an error, see the [troubleshooting](#troubleshooting) section.
Expand All @@ -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=<nameOverride>,app.kubernetes.io/instance=<fullNameOverride>" -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }}

Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
46 changes: 46 additions & 0 deletions samples/helm-deploy/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 12 additions & 0 deletions samples/helm-deploy/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions samples/helm-deploy/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions samples/helm-deploy/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.rbac.serviceAccountName }}
namespace: {{ .Values.namespace }}
31 changes: 31 additions & 0 deletions samples/helm-deploy/values.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
57 changes: 0 additions & 57 deletions samples/helmexample/templates/deployment.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions samples/helmexample/templates/hpa.yaml

This file was deleted.

61 changes: 0 additions & 61 deletions samples/helmexample/templates/ingress.yaml

This file was deleted.

Loading

0 comments on commit df4a3c6

Please sign in to comment.