diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a96aa2af..2d3d8e0a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,3 +43,10 @@ jobs: run: | sleep 120 docker run --network container:psi-todo appropriate/curl -s --retry 10 --retry-connrefused http://localhost:8080/actuator/health + - name: Failure Result + if: ${{ failure() }} + run: | + docker logs mysql + docker logs psi-todo + + diff --git a/todo-app/README.md b/todo-app/README.md index ad11d574..da5aa4f9 100644 --- a/todo-app/README.md +++ b/todo-app/README.md @@ -83,8 +83,8 @@ The following table lists the configurable parameters of the TodoApp swarm clust `BASIC_AUTH_USERNAME` | Username of Basic-Auth | `` `BASIC_AUTH_PASSWORD` | Password of Basic-Auth | `` `MYSQL_IMAGE_TAG` | Image tag for Mysql | `8.0.22` - `MYSQL_USER` | Username of new user to create | `root` - `MYSQL_PASSWORD` | Password for the new user | `root` - `MYSQL_DATABASE` | Name for new database to create | `psi` - `MYSQL_DATA_SRC_PATH` | Host path for persistence mysql data | `` - `MYSQL_DATA_DEST_PATH` | Mount directory path in mysql container | `/var/lib/mysql` \ No newline at end of file + `MYSQL_USER` | Username of new user to create | `` + `MYSQL_PASSWORD` | Password for the new user | `` + `MYSQL_ROOT_PASSWORD` | Password for the root user | `` + `MYSQL_DATABASE` | Name for new database to create | `` + `MYSQL_DATA_SRC_PATH` | Host path for persistence mysql data | `` \ No newline at end of file diff --git a/todo-app/docker-compose.yaml b/todo-app/docker-compose.yaml index e6e1cffe..90b8c3fa 100644 --- a/todo-app/docker-compose.yaml +++ b/todo-app/docker-compose.yaml @@ -3,8 +3,10 @@ services: psimysql: image: mysql:${MYSQL_IMAGE_TAG} environment: + MYSQL_USER: ${MYSQL_USER} MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} psitodoapp: image: psi-todo:${PSI_TODO_IMAGE_TAG:-latest} depends_on: diff --git a/todo-app/env/ci/Docker.env b/todo-app/env/ci/Docker.env index 74108421..6092e2a7 100644 --- a/todo-app/env/ci/Docker.env +++ b/todo-app/env/ci/Docker.env @@ -2,7 +2,7 @@ # Mysql variables MYSQL_IMAGE_TAG=8.0.22 -MYSQL_USER=root -MYSQL_PASSWORD=root -MYSQL_DATABASE=psi -MYSQL_DATA_DEST_PATH=/var/lib/mysql \ No newline at end of file +MYSQL_USER=psi +MYSQL_PASSWORD=psi +MYSQL_ROOT_PASSWORD=root +MYSQL_DATABASE=psi \ No newline at end of file diff --git a/todo-app/env/local/Docker.env b/todo-app/env/local/Docker.env index d205e7e4..bf29899d 100644 --- a/todo-app/env/local/Docker.env +++ b/todo-app/env/local/Docker.env @@ -11,8 +11,8 @@ PSI_TODO_STACK_IMAGE=localhost:5000/psi-todo # Mysql variables MYSQL_IMAGE_TAG=8.0.22 -MYSQL_USER=root -MYSQL_PASSWORD=root +MYSQL_USER=psi +MYSQL_PASSWORD=psi +MYSQL_ROOT_PASSWORD=root MYSQL_DATABASE=psi #MYSQL_DATA_SRC_PATH= -MYSQL_DATA_DEST_PATH=/var/lib/mysql diff --git a/todo-app/env/local/docker-compose-override.yml b/todo-app/env/local/docker-compose-override.yml index 441d9f15..95508af2 100644 --- a/todo-app/env/local/docker-compose-override.yml +++ b/todo-app/env/local/docker-compose-override.yml @@ -3,7 +3,7 @@ services: psimysql: container_name: mysql #Specify a custom container name, rather than a generated default name volumes: - - mysql_data:${MYSQL_DATA_DEST_PATH}:cached # Strong consistency is quite expensive, requiring coordination between all of a files writers to guarantee + - mysql_data:/var/lib/mysql:cached # Strong consistency is quite expensive, requiring coordination between all of a files writers to guarantee # they don’t inappropriately clobber each other’s changes # So Relax consistency guarantees using `cached` mode (Don’t do this in production …) psitodoapp: diff --git a/todo-app/env/local/docker-stack-persistent-compose-override.yml b/todo-app/env/local/docker-stack-persistent-compose-override.yml index 4ca359a1..6a1c5bbf 100644 --- a/todo-app/env/local/docker-stack-persistent-compose-override.yml +++ b/todo-app/env/local/docker-stack-persistent-compose-override.yml @@ -2,7 +2,7 @@ version: "3" services: psimysql: volumes: - - mysql_data:${MYSQL_DATA_DEST_PATH}:cached # Strong consistency is quite expensive, requiring coordination between all of a files writers to guarantee + - mysql_data:/var/lib/mysql:cached # Strong consistency is quite expensive, requiring coordination between all of a files writers to guarantee # they don’t inappropriately clobber each other’s changes # So Relax consistency guarantees using `cached` mode (Don’t do this in production …) volumes: diff --git a/todo-app/k8s/ChocolateyInstallNonAdmin.ps1 b/todo-app/k8s/ChocolateyInstallNonAdmin.ps1 new file mode 100644 index 00000000..369f6266 --- /dev/null +++ b/todo-app/k8s/ChocolateyInstallNonAdmin.ps1 @@ -0,0 +1,13 @@ +# Set directory for installation - Chocolatey does not lock +# down the directory if not the default +$InstallDir='C:\ProgramData\chocoportable' +$env:ChocolateyInstall="$InstallDir" + +# If your PowerShell Execution policy is restrictive, you may +# not be able to get around that. Try setting your session to +# Bypass. +Set-ExecutionPolicy Bypass -Scope Process -Force; + +# All install options - offline, proxy, etc at +# https://chocolatey.org/install +iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) \ No newline at end of file diff --git a/todo-app/k8s/CreateInternalSwitch.ps1 b/todo-app/k8s/CreateInternalSwitch.ps1 new file mode 100644 index 00000000..a9dcdb7f --- /dev/null +++ b/todo-app/k8s/CreateInternalSwitch.ps1 @@ -0,0 +1,2 @@ +# Create an internal switch +New-VMSwitch -name minikube -SwitchType Internal \ No newline at end of file diff --git a/todo-app/k8s/EnableHyperV.ps1 b/todo-app/k8s/EnableHyperV.ps1 new file mode 100644 index 00000000..709ccf42 --- /dev/null +++ b/todo-app/k8s/EnableHyperV.ps1 @@ -0,0 +1,5 @@ +# Check and Enable Hyper-V If not enabled +if ((Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online).State -ne 'Enabled') +{ + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All +} \ No newline at end of file diff --git a/todo-app/k8s/README.md b/todo-app/k8s/README.md index 80b71021..8a0b65b6 100644 --- a/todo-app/k8s/README.md +++ b/todo-app/k8s/README.md @@ -1,55 +1,50 @@ -# Deploy Todo Application in K8s cluster using helm +# Deploy Todo Application to K8s cluster using helm -- Setup minikube - https://minikube.sigs.k8s.io/docs/start/ +- Local Deployment +## Local Deployment ## + +- Setup minikube + + Install Dependencies and run minikube + + ```bash + bash setup.sh bootlocal + ``` + - Link host docker client to the VM's docker daemon - ```bash - eval $(minikube docker-env) - ``` + ```bash + eval $(minikube docker-env) + ``` - Build [Build & Create Docker Image](../README.md#build) - Deploy mysql - - ```bash - helm install mysql ./mysql -f env//mysql-secret.yaml - ``` - or - - ```bash - helm install mysql ./mysql -f env//mysql-secret.yaml -f env//mysql-values.yaml - ``` + + [Deploy MySql using helm](mysql/README.md#Installing%20the%20Chart) - Deploy Todo-app - ```bash - helm install psi-todo ./psi-todo - ``` - or - - ```bash - helm install psi-todo ./psi-todo -f env//psi-todo-secret.yaml -f env//psi-todo-values.yaml - ``` + [Deploy Todo App using helm](psi-todo/README.md#Installing%20the%20Chart) - Verify all pods are up and running - ```bash - $ kubectl get pods - NAME READY STATUS RESTARTS AGE - psi-todo-6f4f69b7d7-8t8kg 1/1 Running 0 92m - mysql-58b87bf444-pshmk 1/1 Running 0 92m - - ``` + ```bash + $ kubectl get pods + NAME READY STATUS RESTARTS AGE + psi-todo-6f4f69b7d7-8t8kg 1/1 Running 0 92m + mysql-58b87bf444-pshmk 1/1 Running 0 92m + + ``` - Execute below command in a separate terminal which creates a route to services deployed with type LoadBalancer and sets their Ingress to their ClusterIP. - ```bash - minikube tunnel - ``` + ```bash + minikube tunnel + ``` - Access swagger api endpoint with below url. - http://localhost:8080/swagger-ui/ \ No newline at end of file + http://localhost:8080/swagger-ui/ diff --git a/todo-app/k8s/env/local/mysql-secret.yaml b/todo-app/k8s/env/local/mysql-secret.yaml deleted file mode 100644 index fcb8aed6..00000000 --- a/todo-app/k8s/env/local/mysql-secret.yaml +++ /dev/null @@ -1,3 +0,0 @@ -mysqlUsername: root -mysqlPassword: root - diff --git a/todo-app/k8s/env/local/mysql-values.yaml b/todo-app/k8s/env/local/mysql-values.yaml deleted file mode 100644 index cdcd811d..00000000 --- a/todo-app/k8s/env/local/mysql-values.yaml +++ /dev/null @@ -1,7 +0,0 @@ -persistence: - local: true - storageClass: local - accessMode: - - ReadWriteOnce - size: 1Gi - hostPath: /mnt/data \ No newline at end of file diff --git a/todo-app/k8s/mysql/README.md b/todo-app/k8s/mysql/README.md new file mode 100644 index 00000000..2a47ef23 --- /dev/null +++ b/todo-app/k8s/mysql/README.md @@ -0,0 +1,77 @@ +# MySql Helm Chart + + +## Introduction + +This chart bootstraps a single node MySQL deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +## Prerequisites + +- Kubernetes 1.19.2 +- PV provisioner support in the underlying infrastructure + +## Installing the Chart + +To install the chart with the release name `mysql` with respective environment secret file: + +```bash +# Verify the configuration +$ helm install --dry-run --debug mysql mysql -f mysql/env//secrets.yaml + +# Install chart +$ helm install mysql mysql -f mysql/env//secrets.yaml +``` + +To install the chart with the release name `mysql` with respective environment secret and configuration file: + +```bash +# Verify the configuration +$ helm install --dry-run --debug mysql mysql -f mysql/env//secrets.yaml -f mysql/env//values.yaml + +# Install chart +$ helm install mysql mysql -f mysql/env//secrets.yaml -f mysql/env//values.yaml +``` + +## Uninstalling the Chart + +To uninstall/delete the `mysql` deployment: + +```bash +$ helm uninstall mysql +``` + +## Configuration + +The following table lists the configurable parameters of the MySQL chart and their default values. + +| Parameter | Description | Default | +| -------------------------------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------- | +| `replica` | Number of instance to run at any time | 1 | +| `image` | `mysql` image configuration. | ` ` | +| `image.repository` | `mysql` image repository. | `mysql`| +| `image.pullPolicy` | `mysql` image pull policy. | `IfNotPresent`| +| `image.tag` | `mysql` image tag. | `8.0.22`| +| `service` | `mysql` service configuration | ` ` | +| `service.type` | Kubernetes service type | `ClusterIP`| +| `service.port` | Service Port to be exposed outside | 3306 | +| `resources` | `mysql` CPU/Memory resource requests/limits | `{}` | +| `persistence` | persistence is to recover data after pod kill | `{}` | +| `persistence.enabled` | persistence is enabled or not | `false ` | +| `persistence.storageClass` | Type of persistent volume claim | ` ` | +| `persistence.accessMode` | ReadWriteOnce or ReadOnly | ` ` | +| `persistence.size` | Size of persistent volume claim | ` ` | +| `persistence.hostPath` | HostPath of the volume to mount | ` ` | +| `config` | Configuration for mysql | `{ database: psi }` | +| `config.database` | Database name | `psi`| +| `username` | Database user name | ` ` | +| `password` | Database password | ` ` | +| `rootPassword` | Database root user password | ` ` | +| `nodeAffinity` | Assign Pods to Nodes using Node Affinity | `[]` | + + + +## Persistence + +A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like a node is a cluster resource. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV, so even if the application pod gets down still the backend data will be retained and when applicatin pod will be up then , persisted data can be accessed. + +PersistentVolume will be created if `persistence.enabled` is set to `true` and if true then data will be mounted into specified directory. In order to disable this functionality `persistence.enabled` should be set to `false`. diff --git a/todo-app/k8s/mysql/env/local/secrets.yaml b/todo-app/k8s/mysql/env/local/secrets.yaml new file mode 100644 index 00000000..75887fc8 --- /dev/null +++ b/todo-app/k8s/mysql/env/local/secrets.yaml @@ -0,0 +1,4 @@ +username: psi +password: psi +rootPassword: root + diff --git a/todo-app/k8s/mysql/env/local/values.yaml b/todo-app/k8s/mysql/env/local/values.yaml new file mode 100644 index 00000000..ede4815b --- /dev/null +++ b/todo-app/k8s/mysql/env/local/values.yaml @@ -0,0 +1,16 @@ +nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - minikube + +persistence: + enabled: true + storageClass: local + accessMode: + - ReadWriteOnce + size: 1Gi + hostPath: /mnt/data \ No newline at end of file diff --git a/todo-app/k8s/mysql/templates/config.yaml b/todo-app/k8s/mysql/templates/config.yaml index 616a7149..2afebf3c 100644 --- a/todo-app/k8s/mysql/templates/config.yaml +++ b/todo-app/k8s/mysql/templates/config.yaml @@ -8,6 +8,9 @@ metadata: release: "{{ .Release.Name }}" data: url: {{ template "mysql.fullname" . }} -{{- range $key, $val := .Values.mysqlConfig }} +{{- if not .Values.config.database }} +{{- fail "Database name is required" }} +{{- end }} +{{- range $key, $val := .Values.config }} {{ $key }}: {{ $val | quote }} {{- end }} \ No newline at end of file diff --git a/todo-app/k8s/mysql/templates/deployment.yaml b/todo-app/k8s/mysql/templates/deployment.yaml index 2e79a7fe..0dfc0e07 100644 --- a/todo-app/k8s/mysql/templates/deployment.yaml +++ b/todo-app/k8s/mysql/templates/deployment.yaml @@ -4,7 +4,7 @@ metadata: name: {{ include "mysql.fullname" . }} labels: {{- include "mysql.labels" . | nindent 4 }} spec: - replicas: {{ .Values.replicaCount }} + replicas: {{ .Values.replica | default 1 }} selector: matchLabels: {{- include "mysql.selectorLabels" . | nindent 6 }} @@ -12,24 +12,16 @@ spec: metadata: labels: {{- include "mysql.selectorLabels" . | nindent 8 }} spec: + {{- if .Values.nodeAffinity }} affinity: + {{- end }} + {{- with .Values.nodeAffinity }} nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: kubernetes.io/hostname - operator: In - values: -{{- if .Values.affinityNodes -}} - {{- range .Values.affinityNodes }} - - {{ . }} - {{- end }} -{{else}} - - {{ default "minikube" }} -{{end}} +{{ toYaml . | indent 10 }} + {{- end }} containers: - name: {{ .Chart.Name }} - image: {{ .Values.image.repository }}:{{ .Values.image.tag }} + image: "{{ .Values.image.repository | default .Chart.Name }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: tcp @@ -37,15 +29,27 @@ spec: livenessProbe: tcpSocket: port: tcp + {{- if .Values.persistence.enabled }} volumeMounts: - name: mysql-storage - mountPath: /var/lib/mysql + mountPath: /var/lib/mysql + {{- end }} env: - - name: MYSQL_ROOT_PASSWORD + - name: MYSQL_USER + valueFrom: + secretKeyRef: + key: username + name: {{ template "mysql.fullname" . }}-secret + - name: MYSQL_PASSWORD valueFrom: secretKeyRef: key: password name: {{ template "mysql.fullname" . }}-secret + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + key: root-password + name: {{ template "mysql.fullname" . }}-secret - name: MYSQL_DATABASE valueFrom: configMapKeyRef: @@ -53,9 +57,9 @@ spec: name: {{ template "mysql.fullname" . }}-config resources: {{- toYaml .Values.resources | nindent 12 }} + {{- if .Values.persistence.enabled }} volumes: - name: mysql-storage - {{- if .Values.persistence.local }} persistentVolumeClaim: claimName: {{ template "mysql.fullname" . }}-claim - {{end}} \ No newline at end of file + {{end}} \ No newline at end of file diff --git a/todo-app/k8s/mysql/templates/pvc.yaml b/todo-app/k8s/mysql/templates/pvc.yaml index 9c7b53c3..06565492 100644 --- a/todo-app/k8s/mysql/templates/pvc.yaml +++ b/todo-app/k8s/mysql/templates/pvc.yaml @@ -1,4 +1,4 @@ -{{- if .Values.persistence }} +{{- if .Values.persistence.enabled }} kind: PersistentVolume apiVersion: v1 metadata: @@ -14,25 +14,16 @@ spec: - {{ . }} {{end}} capacity: - storage: {{ .Values.persistence.size }} -{{- if .Values.persistence.local }} + storage: {{ .Values.persistence.size }} hostPath: - path: {{ .Values.persistence.hostPath | required "Local path is required" | quote }} -{{end}} + path: {{ .Values.persistence.hostPath | required "Host path is required" | quote }} + {{- if .Values.nodeAffinity }} nodeAffinity: + {{- end }} + {{- with .Values.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution }} required: - nodeSelectorTerms: - - matchExpressions: - - key: kubernetes.io/hostname - operator: In - values: -{{- if .Values.affinityNodes -}} - {{- range .Values.affinityNodes }} - - {{ . }} - {{- end }} -{{else}} - - {{ default "minikube" }} -{{end}} +{{ toYaml . | indent 10 }} + {{- end }} --- kind: PersistentVolumeClaim apiVersion: v1 diff --git a/todo-app/k8s/mysql/templates/secret.yaml b/todo-app/k8s/mysql/templates/secret.yaml index 6cf9ca29..9f4777f8 100644 --- a/todo-app/k8s/mysql/templates/secret.yaml +++ b/todo-app/k8s/mysql/templates/secret.yaml @@ -8,5 +8,6 @@ metadata: release: "{{ .Release.Name }}" type: Opaque data: - username: {{ .Values.mysqlUsername | required "Mysql username is required" | b64enc }} - password: {{ .Values.mysqlPassword | required "Mysql password is required" | b64enc }} \ No newline at end of file + username: {{ .Values.username | required "Mysql username is required" | b64enc }} + password: {{ .Values.password | required "Mysql password is required" | b64enc }} + root-password: {{ .Values.rootPassword | required "Mysql root user password is required" | b64enc }} \ No newline at end of file diff --git a/todo-app/k8s/mysql/values.yaml b/todo-app/k8s/mysql/values.yaml index 375e7f3f..85727067 100644 --- a/todo-app/k8s/mysql/values.yaml +++ b/todo-app/k8s/mysql/values.yaml @@ -1,9 +1,9 @@ #Default values fo mysql -replicaCount: 1 +#replica: 1 image: - repository: mysql +# repository: mysql pullPolicy: IfNotPresent - tag: "8.0.22" +# tag: "8.0.22" service: type: ClusterIP @@ -19,18 +19,24 @@ resources: {} #persistence is to recover data after pod kill persistence: {} - #local: false + #enabled: false #storageClass: local #accessMode: # - ReadWriteOnce #size: 1Gi #hostPath: /mnt/data -#mysqlConfig :- Configuration for mysql +#config :- Configuration for mysql #required url & database -mysqlConfig: +config: database: psi -# affinityNodes is the nodes list in which pod will deploy -# default - minikube -affinityNodes: [] \ No newline at end of file + +# Database user name and password +#username: +#password: +#rootPassword: + + +# nodeAffinity policy +nodeAffinity: {} \ No newline at end of file diff --git a/todo-app/k8s/psi-todo/README.md b/todo-app/k8s/psi-todo/README.md new file mode 100644 index 00000000..ad786c83 --- /dev/null +++ b/todo-app/k8s/psi-todo/README.md @@ -0,0 +1,81 @@ +# Todo App Helm Chart + + +## Introduction + +This chart bootstraps a single node Todo App deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +## Prerequisites + +- MySql + +## Installing the Chart + +To install the chart with the release name `psi-todo`: + +```bash +# Verify the configuration +$ helm install --dry-run --debug psi-todo psi-todo + +# Install chart +$ helm install psi-todo psi-todo +``` + +To install the chart with the release name `psi-todo` with respective environment secret and configuration file: + +```bash +# Verify the configuration +$ helm install --dry-run --debug psi-todo psi-todo -f psi-todo/env//secrets.yaml -f psi-todo/env//values.yaml + +# Install chart +$ helm install psi-todo psi-todo -f psi-todo/env//secrets.yaml -f psi-todo/env//values.yaml +``` + +## Uninstalling the Chart + +To uninstall/delete the `psi-todo` deployment: + +```bash +$ helm uninstall psi-todo +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release completely. + +## Configuration + +The following table lists the configurable parameters of the PSI-TODO chart and their default values. + +| Parameter | Description | Default | +| -------------------------------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------- | +| `replica` | Number of instance to run at any time | 1 | +| `image` | `psi-todo` image configuration. | ` ` | +| `image.repository` | `psi-todo` image repository. | `psi-todo`| +| `image.pullPolicy` | `psi-todo` image pull policy. | `Never`| +| `image.tag` | `psi-todo` image tag. | `1.0.0`| +| `livenessProbe` | Indicates whether the container is running. | ` {}` | +| `service` | Kubernetes service configuration. | ` ` | +| `service.type` | ServiceTypes allow you to specify what kind of Service you want. | `LoadBalancer` | +| `service.port` | Port internal to Kubernetes . | 8080 | +| `service.nodeport` | NodePort gives you the freedom to set up your own load balancing solution. | 30000| +| `mysqlRef` | mysqlRef is for inject secret & config of mysql. | "" | +| `mysqlRef` | mysqlRef is for inject secret & config of mysql. | "" | +| `resources` | `psi-todo` CPU/Memory resource requests/limits | `{}` | +| `initContainers` | Init containers can contain utilities or setup scripts not present in an app image | ` ` | +| `initContainers.dbWait` | dbWait until mysql is not up | ` ` | +| `initContainers.dbWait.image` | image for running init container | `busybox ` | +| `initContainers.dbWait.tag` | image tag for running init container | `latest ` | +| `initContainers.dbWait.imagePullPolicy` | image pull policy for running init container | `IfNotPresent ` | +| `security` | Spring security | ` ` | +| `security.basicAuth` | Spring security of type basicauth | ` ` | +| `security.basicAuth.username` | Spring security of type basicauth username | ` ` | +| `security.basicAuth.password` | Spring security of type basicauth password | ` ` | +| `config` | Config for todoApp | ` ` | +| `config.securityBasicAuthEnable` | Enable/ Disable basic-auth |`false`| + + + + + + + + diff --git a/todo-app/k8s/env/local/psi-todo-secret.yaml b/todo-app/k8s/psi-todo/env/local/secrets.yaml similarity index 100% rename from todo-app/k8s/env/local/psi-todo-secret.yaml rename to todo-app/k8s/psi-todo/env/local/secrets.yaml diff --git a/todo-app/k8s/env/local/psi-todo-values.yaml b/todo-app/k8s/psi-todo/env/local/values.yaml similarity index 72% rename from todo-app/k8s/env/local/psi-todo-values.yaml rename to todo-app/k8s/psi-todo/env/local/values.yaml index e683979d..0282505b 100644 --- a/todo-app/k8s/env/local/psi-todo-values.yaml +++ b/todo-app/k8s/psi-todo/env/local/values.yaml @@ -1,2 +1,2 @@ -todoConfig: +config: securityBasicAuthEnable: true \ No newline at end of file diff --git a/todo-app/k8s/psi-todo/templates/config.yaml b/todo-app/k8s/psi-todo/templates/config.yaml index 53137eec..6d2ca4d2 100644 --- a/todo-app/k8s/psi-todo/templates/config.yaml +++ b/todo-app/k8s/psi-todo/templates/config.yaml @@ -7,6 +7,6 @@ metadata: chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" data: -{{- range $key, $val := .Values.todoConfig }} +{{- range $key, $val := .Values.config }} {{ $key }}: {{ $val | quote }} {{- end }} \ No newline at end of file diff --git a/todo-app/k8s/psi-todo/templates/deployment.yaml b/todo-app/k8s/psi-todo/templates/deployment.yaml index 2abd691e..e459d980 100644 --- a/todo-app/k8s/psi-todo/templates/deployment.yaml +++ b/todo-app/k8s/psi-todo/templates/deployment.yaml @@ -4,7 +4,7 @@ metadata: name: {{ include "psi-todo.fullname" . }} labels: {{- include "psi-todo.labels" . | nindent 4 }} spec: - replicas: {{ .Values.replicaCount }} + replicas: {{ .Values.replica | default 1 }} selector: matchLabels: {{- include "psi-todo.selectorLabels" . | nindent 6 }} @@ -30,7 +30,7 @@ spec: {{end}} containers: - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + image: "{{ .Values.image.repository | default .Chart.Name }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http @@ -73,7 +73,7 @@ spec: configMapKeyRef: key: securityBasicAuthEnable name: {{ include "psi-todo.fullname" . }}-config - {{- if .Values.todoConfig.securityBasicAuthEnable }} + {{- if .Values.config.securityBasicAuthEnable }} - name: PSI_TODO_SECURITY_BASIC_AUTH_USERNAME valueFrom: secretKeyRef: @@ -89,6 +89,6 @@ spec: {{- toYaml .Values.resources | nindent 12 }} initContainers: - name: init-mysql-wait - image: {{ .Values.initContainers.dbWait.image }}:{{ .Values.initContainers.dbWait.tag }} - imagePullPolicy: {{ .Values.initContainers.dbWait.imagePullPolicy }} - command: ['sh', '-c', 'until nslookup mysql; do echo waiting for {{ default "mysql" .Values.mysqlRef }}; sleep 2; done;'] \ No newline at end of file + image: "{{ .Values.initContainers.dbWait.image | default "busybox" }}:{{ .Values.initContainers.dbWait.tag | default "latest" }}" + imagePullPolicy: {{ .Values.initContainers.dbWait.imagePullPolicy | default "IfNotPresent" }} + command: ['sh', '-c', 'until nslookup {{ default "mysql" .Values.mysqlRef }}; do echo waiting for {{ default "mysql" .Values.mysqlRef }}; sleep 2; done;'] \ No newline at end of file diff --git a/todo-app/k8s/psi-todo/templates/secret.yaml b/todo-app/k8s/psi-todo/templates/secret.yaml index 3bea44bb..b369d9e0 100644 --- a/todo-app/k8s/psi-todo/templates/secret.yaml +++ b/todo-app/k8s/psi-todo/templates/secret.yaml @@ -1,4 +1,4 @@ -{{- if .Values.todoConfig.securityBasicAuthEnable -}} +{{- if .Values.config.securityBasicAuthEnable -}} apiVersion: v1 kind: Secret metadata: diff --git a/todo-app/k8s/psi-todo/values.yaml b/todo-app/k8s/psi-todo/values.yaml index e4a892a0..37311bd7 100644 --- a/todo-app/k8s/psi-todo/values.yaml +++ b/todo-app/k8s/psi-todo/values.yaml @@ -1,18 +1,18 @@ #Default values fo Todo app -replicaCount: 1 +replica: 1 image: - repository: psi-todo +# repository: psi-todo pullPolicy: Never - tag: "1.0.0" +# tag: "1.0.0" -livenessProbe: - enabled: false - initialDelaySeconds: 60 - periodSeconds: 30 - timeoutSeconds: 10 - successThreshold: 1 - failureThreshold: 3 +livenessProbe: {} +# enabled: false +# initialDelaySeconds: 60 +# periodSeconds: 30 +# timeoutSeconds: 10 +# successThreshold: 1 +# failureThreshold: 3 service: type: LoadBalancer @@ -31,17 +31,17 @@ resources: {} # memory: 128Mi initContainers: - dbWait: # dbWait until mysql is not up - image: busybox - tag: latest - imagePullPolicy: IfNotPresent + dbWait: {} # dbWait until mysql is not up +# image: busybox +# tag: latest +# imagePullPolicy: IfNotPresent # security :- Spring security -security: - basicAuth: - username: # Basic auth username - password: # Basic auth password +security: {} +# basicAuth: +# username: # Basic auth username +# password: # Basic auth password -# todoConfig :- Config for todoApp -todoConfig: +# config :- Config for todoApp +config: securityBasicAuthEnable: false # Enable/ Disable basic-auth \ No newline at end of file diff --git a/todo-app/k8s/setup.sh b/todo-app/k8s/setup.sh new file mode 100644 index 00000000..902c1db8 --- /dev/null +++ b/todo-app/k8s/setup.sh @@ -0,0 +1,122 @@ +# #!/bin/bash + +me="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" + +exit_if_fail(){ + ret=$? + if [ $ret -ne 0 ]; then + echo "entering if.." + exit $ret + fi +} + +install_helpers_darwin() { + brew --version &> /dev/null || { eval $(if [ "$debug" -eq 1 ]; then echo "curl -fSL"; else echo "curl -fsSL"; fi) https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh; echo -e "\xE2\x9C\x94 Installed helper libraries(brew)\n";exit_if_fail; } +} + +install_helpers_win() { + echo "Install helper libraries(choco)....." + chmod +x ChocolateyInstallNonAdmin.ps1 + powershell.exe -ExecutionPolicy RemoteSigned -File './ChocolateyInstallNonAdmin.ps1' + exit_if_fail +} + +enable_hyperv_win(){ + echo "Enabling Hyper-V if not enabled....." + chmod +x EnableHyperV.ps1 + powershell.exe -ExecutionPolicy RemoteSigned -File './EnableHyperV.ps1' + exit_if_fail; +} +create_internal_swtich(){ + echo "Creating Virtual Switch of type Internal....." + chmod +x CreateInternalSwitch.ps1 + powershell.exe -ExecutionPolicy RemoteSigned -File './CreateInternalSwitch.ps1' + exit_if_fail; +} + +install_helm_darwin() { + helm version &> /dev/null || { echo "Installing helm....."; HOMEBREW_NO_AUTO_UPDATE=1 eval $(if [ "$debug" -eq 1 ]; then echo "brew install -dv"; else echo "brew install -q"; fi) helm;exit_if_fail; } + echo -e "\xE2\x9C\x94 Helm -- $( helm version | awk '{split($0,a," "); print a[1]}' | awk '{split($0,a,":"); print a[2]}'| sed 's/.$//' )"; +} + +install_minikube_darwin() { + minikube version &> /dev/null || { echo "Installing minikube....."; HOMEBREW_NO_AUTO_UPDATE=1 eval $(if [ "$debug" -eq 1 ]; then echo "brew install -dv"; else echo "brew install -q"; fi) minikube; exit_if_fail;} + echo -e "\xE2\x9C\x94 Minikube -- $( minikube version | awk '{split($0,a," "); print a[3]}' )"; +} + +boot_minikube_darwin() { + install_helpers_darwin + install_helm_darwin + install_minikube_darwin + minikube start --kubernetes-version=v1.19.2; + exit_if_fail; +} + +boot_minikube_win() { + enable_hyperv_win + install_helpers_win + docker --version &> /dev/null || { echo "Installing docker for windows.....";choco install docker-for-windows –pre; exit_if_fail;} + minikube --version &> /dev/null || { echo "Installing minikube for windows.....";choco install minikube;exit_if_fail; } + helm --version &> /dev/null || { echo "Installing helm for windows.....";choco install kubernetes-helm;exit_if_fail; } + create_internal_swtich + minikube start --kubernetes-version=v1.19.2 — vm-driver=”hyperv” — hyperv-virtual-switch=”minikube” + exit_if_fail; +} + + +boot_local() { + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "TODO -- Install miinikube & helm" + elif [[ "$OSTYPE" == "darwin"* ]]; then + boot_minikube_darwin + elif [[ "$OSTYPE" == "msys" ]]; then + boot_minikube_win + fi + exit 0; +} + +help() { + echo "Usage: ${me} [OPTIONS] COMMAND" + echo "" + echo "Author:" + echo " PSI Lab Contributors - <$(git config --get remote.origin.url)>" + echo "" + echo "Options:" + echo " --debug, -D Enable debug mode" + echo " --help, -h show help" + echo "" + echo "Commands:" + echo " bootlocal Install and Start Minikube on local" +} + +debug=0 # disable debug + +if [ $# -lt 1 ]; then + help +fi + + +while test -n "$1"; do + case "$1" in + --debug|-D) + if [[ $# -eq 1 ]]; then + help + fi + debug=1 # enable debug + shift + ;; + bootlocal) + if [[ $# -gt 1 ]]; then + echo "Too many args"; + exit 1; + fi + boot_local + shift + ;; + *) + echo "Unrecognized option : ${1}" + help + exit 1; + esac +done +debug=0 # disable debug \ No newline at end of file diff --git a/todo-app/swarm/README.md b/todo-app/swarm/README.md index 3442d9ee..72a87332 100644 --- a/todo-app/swarm/README.md +++ b/todo-app/swarm/README.md @@ -100,9 +100,9 @@ `BASIC_AUTH_USERNAME` | Username of Basic-Auth | `` `BASIC_AUTH_PASSWORD` | Password of Basic-Auth | `` `MYSQL_IMAGE_TAG` | Image tag for Mysql | `8.0.22` - `MYSQL_USER` | Username of new user to create | `root` - `MYSQL_PASSWORD` | Password for the new user | `root` - `MYSQL_DATABASE` | Name for new database to create | `psi` + `MYSQL_USER` | Username of new user to create | `` + `MYSQL_PASSWORD` | Password for the new user | `` + `MYSQL_ROOT_PASSWORD` | Password for the root user | `` + `MYSQL_DATABASE` | Name for new database to create | `` `MYSQL_DATA_SRC_PATH` | Host path for persistence mysql data | `` - `MYSQL_DATA_DEST_PATH` | Mount directory path in mysql container | `/var/lib/mysql` diff --git a/todo-app/swarm/install-dependencies.sh b/todo-app/swarm/install-dependencies.sh index f089b611..70f6fedc 100755 --- a/todo-app/swarm/install-dependencies.sh +++ b/todo-app/swarm/install-dependencies.sh @@ -111,7 +111,7 @@ install_docker_machine() { elif [[ "$OSTYPE" == "msys" ]]; then install_docker_machine_win fi - + exit 0; } install_virtualbox() { @@ -122,6 +122,7 @@ install_virtualbox() { elif [[ "$OSTYPE" == "msys" ]]; then install_virtualbox_win fi + exit 0; } help() { @@ -140,7 +141,7 @@ help() { echo " docker-machine Install Docker machine" } -debug=0 +debug=0 # disable debug if [ $# -lt 1 ]; then help @@ -150,7 +151,10 @@ fi while test -n "$1"; do case "$1" in --debug|-D) - debug=1 + if [[ $# -eq 1 ]]; then + help + fi + debug=1 # enable debug shift ;; all) @@ -187,4 +191,6 @@ while test -n "$1"; do help exit 1; esac -done \ No newline at end of file +done + +debug=0 # disable debug \ No newline at end of file