From b02ef17f1b3062e913f4f03eb292bf494e199561 Mon Sep 17 00:00:00 2001 From: jbris Date: Tue, 12 Dec 2023 23:18:36 +1300 Subject: [PATCH] Adding side modules --- config/config_maps.sh | 23 ++++++ .../configmap/game-env-file.properties | 5 ++ .../configmap/game.properties | 7 ++ .../configmap/ui-env-file.properties | 3 + .../configmap/ui.properties | 4 + config/kustomization.yaml | 7 ++ config/secret.sh | 4 + config/secret/dockercfg-secret.yaml | 8 ++ config/secret/dotfile-secret.yaml | 27 +++++++ config/secret/optional-secret.yaml | 17 +++++ .../secret/serviceaccount-token-secret.yaml | 9 +++ external_ip/init_app.sh | 17 +++++ .../service/load-balancer-example.yaml | 21 ++++++ .../guestbook/frontend-deployment.yaml | 29 ++++++++ .../guestbook/frontend-service.yaml | 19 +++++ .../guestbook/redis-follower-deployment.yaml | 30 ++++++++ .../guestbook/redis-follower-service.yaml | 17 +++++ .../guestbook/redis-leader-deployment.yaml | 30 ++++++++ .../guestbook/redis-leader-service.yaml | 17 +++++ php_redis/init_app.sh | 25 +++++++ php_redis/scale_app.sh | 3 + redis/init_redis.sh | 5 ++ redis/kubectl_clean.sh | 7 ++ redis/kubectl_get.sh | 11 +++ redis/pods/config/example-redis-config.yaml | 8 ++ redis/pods/config/redis-pod.yaml | 33 +++++++++ .../wordpress/mysql-deployment.yaml | 74 +++++++++++++++++++ .../wordpress/wordpress-deployment.yaml | 69 +++++++++++++++++ wordpress/kubectl_apply.sh | 11 +++ wordpress/kubectl_proxy.sh | 3 + wordpress/kustomization.yaml | 7 ++ 31 files changed, 550 insertions(+) create mode 100644 config/config_maps.sh create mode 100644 config/configure-pod-container/configmap/game-env-file.properties create mode 100644 config/configure-pod-container/configmap/game.properties create mode 100644 config/configure-pod-container/configmap/ui-env-file.properties create mode 100644 config/configure-pod-container/configmap/ui.properties create mode 100644 config/kustomization.yaml create mode 100644 config/secret.sh create mode 100644 config/secret/dockercfg-secret.yaml create mode 100644 config/secret/dotfile-secret.yaml create mode 100644 config/secret/optional-secret.yaml create mode 100644 config/secret/serviceaccount-token-secret.yaml create mode 100644 external_ip/init_app.sh create mode 100644 external_ip/service/load-balancer-example.yaml create mode 100644 php_redis/application/guestbook/frontend-deployment.yaml create mode 100644 php_redis/application/guestbook/frontend-service.yaml create mode 100644 php_redis/application/guestbook/redis-follower-deployment.yaml create mode 100644 php_redis/application/guestbook/redis-follower-service.yaml create mode 100644 php_redis/application/guestbook/redis-leader-deployment.yaml create mode 100644 php_redis/application/guestbook/redis-leader-service.yaml create mode 100644 php_redis/init_app.sh create mode 100644 php_redis/scale_app.sh create mode 100644 redis/init_redis.sh create mode 100644 redis/kubectl_clean.sh create mode 100644 redis/kubectl_get.sh create mode 100644 redis/pods/config/example-redis-config.yaml create mode 100644 redis/pods/config/redis-pod.yaml create mode 100644 wordpress/application/wordpress/mysql-deployment.yaml create mode 100644 wordpress/application/wordpress/wordpress-deployment.yaml create mode 100644 wordpress/kubectl_apply.sh create mode 100644 wordpress/kubectl_proxy.sh create mode 100644 wordpress/kustomization.yaml diff --git a/config/config_maps.sh b/config/config_maps.sh new file mode 100644 index 0000000..637a842 --- /dev/null +++ b/config/config_maps.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +mkdir -p configure-pod-container/configmap/ + +wget https://kubernetes.io/examples/configmap/game.properties -O configure-pod-container/configmap/game.properties +wget https://kubernetes.io/examples/configmap/ui.properties -O configure-pod-container/configmap/ui.properties + +kubectl create configmap game-config --from-file=configure-pod-container/configmap/ + +kubectl describe configmaps game-config + +kubectl get configmaps game-config -o yaml + +kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties + +kubectl create configmap game-config-2 --from-file=configure-pod-container/configmap/game.properties --from-file=configure-pod-container/configmap/ui.properties + +kubectl create configmap game-config-env-file \ + --from-env-file=configure-pod-container/configmap/game-env-file.properties + +kubectl get configmap config-multi-env-files -o yaml + +kubectl apply -k . \ No newline at end of file diff --git a/config/configure-pod-container/configmap/game-env-file.properties b/config/configure-pod-container/configmap/game-env-file.properties new file mode 100644 index 0000000..a96a12e --- /dev/null +++ b/config/configure-pod-container/configmap/game-env-file.properties @@ -0,0 +1,5 @@ +enemies=aliens +lives=3 +allowed="true" + +# This comment and the empty line above it are ignored diff --git a/config/configure-pod-container/configmap/game.properties b/config/configure-pod-container/configmap/game.properties new file mode 100644 index 0000000..8ba4184 --- /dev/null +++ b/config/configure-pod-container/configmap/game.properties @@ -0,0 +1,7 @@ +enemies=aliens +lives=3 +enemies.cheat=true +enemies.cheat.level=noGoodRotten +secret.code.passphrase=UUDDLRLRBABAS +secret.code.allowed=true +secret.code.lives=30 \ No newline at end of file diff --git a/config/configure-pod-container/configmap/ui-env-file.properties b/config/configure-pod-container/configmap/ui-env-file.properties new file mode 100644 index 0000000..1b5c769 --- /dev/null +++ b/config/configure-pod-container/configmap/ui-env-file.properties @@ -0,0 +1,3 @@ +color=purple +textmode=true +how=fairlyNice diff --git a/config/configure-pod-container/configmap/ui.properties b/config/configure-pod-container/configmap/ui.properties new file mode 100644 index 0000000..487bea0 --- /dev/null +++ b/config/configure-pod-container/configmap/ui.properties @@ -0,0 +1,4 @@ +color.good=purple +color.bad=yellow +allow.textmode=true +how.nice.to.look=fairlyNice diff --git a/config/kustomization.yaml b/config/kustomization.yaml new file mode 100644 index 0000000..f74058c --- /dev/null +++ b/config/kustomization.yaml @@ -0,0 +1,7 @@ +configMapGenerator: +- name: game-config-4 + options: + labels: + game-config: config-4 + files: + - configure-pod-container/configmap/game.properties diff --git a/config/secret.sh b/config/secret.sh new file mode 100644 index 0000000..9f737e1 --- /dev/null +++ b/config/secret.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +kubectl create secret generic empty-secret +kubectl get secret empty-secret \ No newline at end of file diff --git a/config/secret/dockercfg-secret.yaml b/config/secret/dockercfg-secret.yaml new file mode 100644 index 0000000..20b7626 --- /dev/null +++ b/config/secret/dockercfg-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-dockercfg +type: kubernetes.io/dockercfg +data: + .dockercfg: | + eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo= \ No newline at end of file diff --git a/config/secret/dotfile-secret.yaml b/config/secret/dotfile-secret.yaml new file mode 100644 index 0000000..d25d603 --- /dev/null +++ b/config/secret/dotfile-secret.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: Secret +metadata: + name: dotfile-secret +data: + .secret-file: dmFsdWUtMg0KDQo= +--- +apiVersion: v1 +kind: Pod +metadata: + name: secret-dotfiles-pod +spec: + volumes: + - name: secret-volume + secret: + secretName: dotfile-secret + containers: + - name: dotfile-test-container + image: registry.k8s.io/busybox + command: + - ls + - "-l" + - "/etc/secret-volume" + volumeMounts: + - name: secret-volume + readOnly: true + mountPath: "/etc/secret-volume" \ No newline at end of file diff --git a/config/secret/optional-secret.yaml b/config/secret/optional-secret.yaml new file mode 100644 index 0000000..28a50ac --- /dev/null +++ b/config/secret/optional-secret.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mypod +spec: + containers: + - name: mypod + image: redis + volumeMounts: + - name: foo + mountPath: "/etc/foo" + readOnly: true + volumes: + - name: foo + secret: + secretName: mysecret + optional: true \ No newline at end of file diff --git a/config/secret/serviceaccount-token-secret.yaml b/config/secret/serviceaccount-token-secret.yaml new file mode 100644 index 0000000..d1207f9 --- /dev/null +++ b/config/secret/serviceaccount-token-secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-sa-sample + annotations: + kubernetes.io/service-account.name: "sa-name" +type: kubernetes.io/service-account-token +data: + extra: YmFyCg== \ No newline at end of file diff --git a/external_ip/init_app.sh b/external_ip/init_app.sh new file mode 100644 index 0000000..ae8e13e --- /dev/null +++ b/external_ip/init_app.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +kubectl apply -f service/load-balancer-example.yaml + +kubectl get deployments hello-world +kubectl describe deployments hello-world + +kubectl get replicasets +kubectl describe replicasets + +kubectl expose deployment hello-world --type=LoadBalancer --name=my-service + +kubectl get services my-service + +kubectl describe services my-service + +kubectl get pods --output=wide \ No newline at end of file diff --git a/external_ip/service/load-balancer-example.yaml b/external_ip/service/load-balancer-example.yaml new file mode 100644 index 0000000..a774d59 --- /dev/null +++ b/external_ip/service/load-balancer-example.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/name: load-balancer-example + name: hello-world +spec: + replicas: 5 + selector: + matchLabels: + app.kubernetes.io/name: load-balancer-example + template: + metadata: + labels: + app.kubernetes.io/name: load-balancer-example + spec: + containers: + - image: gcr.io/google-samples/node-hello:1.0 + name: hello-world + ports: + - containerPort: 8080 diff --git a/php_redis/application/guestbook/frontend-deployment.yaml b/php_redis/application/guestbook/frontend-deployment.yaml new file mode 100644 index 0000000..e6cfb3e --- /dev/null +++ b/php_redis/application/guestbook/frontend-deployment.yaml @@ -0,0 +1,29 @@ +# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: 3 + selector: + matchLabels: + app: guestbook + tier: frontend + template: + metadata: + labels: + app: guestbook + tier: frontend + spec: + containers: + - name: php-redis + image: gcr.io/google_samples/gb-frontend:v5 + env: + - name: GET_HOSTS_FROM + value: "dns" + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 80 \ No newline at end of file diff --git a/php_redis/application/guestbook/frontend-service.yaml b/php_redis/application/guestbook/frontend-service.yaml new file mode 100644 index 0000000..a9e74bb --- /dev/null +++ b/php_redis/application/guestbook/frontend-service.yaml @@ -0,0 +1,19 @@ +# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook +apiVersion: v1 +kind: Service +metadata: + name: frontend + labels: + app: guestbook + tier: frontend +spec: + # if your cluster supports it, uncomment the following to automatically create + # an external load-balanced IP for the frontend service. + # type: LoadBalancer + #type: LoadBalancer + ports: + # the port that this service should serve on + - port: 80 + selector: + app: guestbook + tier: frontend \ No newline at end of file diff --git a/php_redis/application/guestbook/redis-follower-deployment.yaml b/php_redis/application/guestbook/redis-follower-deployment.yaml new file mode 100644 index 0000000..ec36f3f --- /dev/null +++ b/php_redis/application/guestbook/redis-follower-deployment.yaml @@ -0,0 +1,30 @@ +# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-follower + labels: + app: redis + role: follower + tier: backend +spec: + replicas: 2 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + role: follower + tier: backend + spec: + containers: + - name: follower + image: gcr.io/google_samples/gb-redis-follower:v2 + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 6379 \ No newline at end of file diff --git a/php_redis/application/guestbook/redis-follower-service.yaml b/php_redis/application/guestbook/redis-follower-service.yaml new file mode 100644 index 0000000..e377c50 --- /dev/null +++ b/php_redis/application/guestbook/redis-follower-service.yaml @@ -0,0 +1,17 @@ +# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook +apiVersion: v1 +kind: Service +metadata: + name: redis-follower + labels: + app: redis + role: follower + tier: backend +spec: + ports: + # the port that this service should serve on + - port: 6379 + selector: + app: redis + role: follower + tier: backend \ No newline at end of file diff --git a/php_redis/application/guestbook/redis-leader-deployment.yaml b/php_redis/application/guestbook/redis-leader-deployment.yaml new file mode 100644 index 0000000..6dc5707 --- /dev/null +++ b/php_redis/application/guestbook/redis-leader-deployment.yaml @@ -0,0 +1,30 @@ +# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-leader + labels: + app: redis + role: leader + tier: backend +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + role: leader + tier: backend + spec: + containers: + - name: leader + image: "docker.io/redis:6.0.5" + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 6379 \ No newline at end of file diff --git a/php_redis/application/guestbook/redis-leader-service.yaml b/php_redis/application/guestbook/redis-leader-service.yaml new file mode 100644 index 0000000..3b17bcc --- /dev/null +++ b/php_redis/application/guestbook/redis-leader-service.yaml @@ -0,0 +1,17 @@ +# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook +apiVersion: v1 +kind: Service +metadata: + name: redis-leader + labels: + app: redis + role: leader + tier: backend +spec: + ports: + - port: 6379 + targetPort: 6379 + selector: + app: redis + role: leader + tier: backend \ No newline at end of file diff --git a/php_redis/init_app.sh b/php_redis/init_app.sh new file mode 100644 index 0000000..d7ccb71 --- /dev/null +++ b/php_redis/init_app.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +kubectl apply -f application/guestbook/redis-leader-deployment.yaml + +kubectl apply -f application/guestbook/redis-leader-service.yaml + +kubectl apply -f application/guestbook/redis-follower-deployment.yaml + +kubectl apply -f application/guestbook/redis-follower-service.yaml + +kubectl apply -f application/guestbook/frontend-deployment.yaml + +kubectl apply -f application/guestbook/frontend-service.yaml + +kubectl get pods -l app=guestbook -l tier=frontend + +kubectl get pods + +# kubectl logs -f deployment/redis-leader + +kubectl port-forward svc/frontend 8080:80 + +kubectl get service + +kubectl get service frontend \ No newline at end of file diff --git a/php_redis/scale_app.sh b/php_redis/scale_app.sh new file mode 100644 index 0000000..fd446f5 --- /dev/null +++ b/php_redis/scale_app.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +kubectl scale deployment frontend --replicas=5 \ No newline at end of file diff --git a/redis/init_redis.sh b/redis/init_redis.sh new file mode 100644 index 0000000..5da5c43 --- /dev/null +++ b/redis/init_redis.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +kubectl apply -f example-redis-config.yaml + +kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml \ No newline at end of file diff --git a/redis/kubectl_clean.sh b/redis/kubectl_clean.sh new file mode 100644 index 0000000..8fbb3f0 --- /dev/null +++ b/redis/kubectl_clean.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +kubectl delete pod/redis configmap/example-redis-config + +kubectl delete pod redis + +kubectl delete pod/redis configmap/example-redis-config \ No newline at end of file diff --git a/redis/kubectl_get.sh b/redis/kubectl_get.sh new file mode 100644 index 0000000..7ce9de7 --- /dev/null +++ b/redis/kubectl_get.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +kubectl get pod/redis configmap/example-redis-config + +kubectl describe configmap/example-redis-config + +kubectl exec -it redis -- redis-cli + +# CONFIG GET maxmemory + +kubectl apply -f pods/config/example-redis-config.yaml \ No newline at end of file diff --git a/redis/pods/config/example-redis-config.yaml b/redis/pods/config/example-redis-config.yaml new file mode 100644 index 0000000..3ee4074 --- /dev/null +++ b/redis/pods/config/example-redis-config.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: example-redis-config +data: + redis-config: | + maxmemory 2mb + maxmemory-policy allkeys-lru \ No newline at end of file diff --git a/redis/pods/config/redis-pod.yaml b/redis/pods/config/redis-pod.yaml new file mode 100644 index 0000000..a4aad7e --- /dev/null +++ b/redis/pods/config/redis-pod.yaml @@ -0,0 +1,33 @@ +apiVersion: v1 +kind: Pod +metadata: + name: redis +spec: + containers: + - name: redis + image: redis:5.0.4 + command: + - redis-server + - "/redis-master/redis.conf" + env: + - name: MASTER + value: "true" + ports: + - containerPort: 6379 + resources: + limits: + cpu: "0.1" + volumeMounts: + - mountPath: /redis-master-data + name: data + - mountPath: /redis-master + name: config + volumes: + - name: data + emptyDir: {} + - name: config + configMap: + name: example-redis-config + items: + - key: redis-config + path: redis.conf \ No newline at end of file diff --git a/wordpress/application/wordpress/mysql-deployment.yaml b/wordpress/application/wordpress/mysql-deployment.yaml new file mode 100644 index 0000000..a3b007e --- /dev/null +++ b/wordpress/application/wordpress/mysql-deployment.yaml @@ -0,0 +1,74 @@ +apiVersion: v1 +kind: Service +metadata: + name: wordpress-mysql + labels: + app: wordpress +spec: + ports: + - port: 3306 + selector: + app: wordpress + tier: mysql + clusterIP: None +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mysql-pv-claim + labels: + app: wordpress +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 20Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress-mysql + labels: + app: wordpress +spec: + selector: + matchLabels: + app: wordpress + tier: mysql + strategy: + type: Recreate + template: + metadata: + labels: + app: wordpress + tier: mysql + spec: + containers: + - image: mysql:8.0 + name: mysql + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-pass + key: password + - name: MYSQL_DATABASE + value: wordpress + - name: MYSQL_USER + value: wordpress + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-pass + key: password + ports: + - containerPort: 3306 + name: mysql + volumeMounts: + - name: mysql-persistent-storage + mountPath: /var/lib/mysql + volumes: + - name: mysql-persistent-storage + persistentVolumeClaim: + claimName: mysql-pv-claim diff --git a/wordpress/application/wordpress/wordpress-deployment.yaml b/wordpress/application/wordpress/wordpress-deployment.yaml new file mode 100644 index 0000000..43d9525 --- /dev/null +++ b/wordpress/application/wordpress/wordpress-deployment.yaml @@ -0,0 +1,69 @@ +apiVersion: v1 +kind: Service +metadata: + name: wordpress + labels: + app: wordpress +spec: + ports: + - port: 80 + selector: + app: wordpress + tier: frontend + type: LoadBalancer +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: wp-pv-claim + labels: + app: wordpress +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 20Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress + labels: + app: wordpress +spec: + selector: + matchLabels: + app: wordpress + tier: frontend + strategy: + type: Recreate + template: + metadata: + labels: + app: wordpress + tier: frontend + spec: + containers: + - image: wordpress:6.2.1-apache + name: wordpress + env: + - name: WORDPRESS_DB_HOST + value: wordpress-mysql + - name: WORDPRESS_DB_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-pass + key: password + - name: WORDPRESS_DB_USER + value: wordpress + ports: + - containerPort: 80 + name: wordpress + volumeMounts: + - name: wordpress-persistent-storage + mountPath: /var/www/html + volumes: + - name: wordpress-persistent-storage + persistentVolumeClaim: + claimName: wp-pv-claim diff --git a/wordpress/kubectl_apply.sh b/wordpress/kubectl_apply.sh new file mode 100644 index 0000000..6662342 --- /dev/null +++ b/wordpress/kubectl_apply.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +kubectl apply -k ./ + +kubectl get secrets + +kubectl get pvc + +kubectl get pods + +kubectl get services wordpress diff --git a/wordpress/kubectl_proxy.sh b/wordpress/kubectl_proxy.sh new file mode 100644 index 0000000..d3229fa --- /dev/null +++ b/wordpress/kubectl_proxy.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +minikube service wordpress --url \ No newline at end of file diff --git a/wordpress/kustomization.yaml b/wordpress/kustomization.yaml new file mode 100644 index 0000000..2a01519 --- /dev/null +++ b/wordpress/kustomization.yaml @@ -0,0 +1,7 @@ +secretGenerator: +- name: mysql-pass + literals: + - password=YOUR_PASSWORD +resources: + - ./application/wordpress/mysql-deployment.yaml + - ./application/wordpress/wordpress-deployment.yaml