From 0adf65a90af4a6a348857001f38054239325eefa Mon Sep 17 00:00:00 2001 From: Prasad Honrao Date: Thu, 24 Oct 2024 16:11:41 +0100 Subject: [PATCH] Update k8s YAMLs --- .k8s/emptydir-volume/database/configmap.yaml | 2 +- .k8s/emptydir-volume/database/deployment.yaml | 6 ++-- .k8s/emptydir-volume/database/install.sh | 4 +-- .k8s/emptydir-volume/database/secret.yaml | 4 +-- .../database/service-nodeport.yaml | 14 --------- .../{service-clusterip.yaml => service.yaml} | 2 +- .k8s/emptydir-volume/database/uninstall.sh | 4 +-- .k8s/emptydir-volume/install.sh | 9 ++++-- .k8s/emptydir-volume/network/ingress.yaml | 30 +++++++++++++++++++ .k8s/emptydir-volume/network/install.sh | 4 +++ .k8s/emptydir-volume/network/uninstall.sh | 2 ++ .k8s/emptydir-volume/uninstall.sh | 9 ++++-- .k8s/emptydir-volume/webapi/configmap.yaml | 2 +- .k8s/emptydir-volume/webapi/install.sh | 3 +- .../webapi/service-loadbalancer.yaml | 13 -------- .../{service-nodeport.yaml => service.yaml} | 4 +-- .k8s/emptydir-volume/webapi/uninstall.sh | 3 +- .k8s/emptydir-volume/webapp/configmap.yaml | 2 +- .k8s/emptydir-volume/webapp/install.sh | 3 +- .../webapp/service-loadbalancer.yaml | 13 -------- .../{service-nodeport.yaml => service.yaml} | 4 +-- .k8s/emptydir-volume/webapp/uninstall.sh | 3 +- 22 files changed, 67 insertions(+), 73 deletions(-) delete mode 100644 .k8s/emptydir-volume/database/service-nodeport.yaml rename .k8s/emptydir-volume/database/{service-clusterip.yaml => service.yaml} (83%) create mode 100644 .k8s/emptydir-volume/network/ingress.yaml create mode 100644 .k8s/emptydir-volume/network/install.sh create mode 100644 .k8s/emptydir-volume/network/uninstall.sh delete mode 100644 .k8s/emptydir-volume/webapi/service-loadbalancer.yaml rename .k8s/emptydir-volume/webapi/{service-nodeport.yaml => service.yaml} (69%) delete mode 100644 .k8s/emptydir-volume/webapp/service-loadbalancer.yaml rename .k8s/emptydir-volume/webapp/{service-nodeport.yaml => service.yaml} (69%) diff --git a/.k8s/emptydir-volume/database/configmap.yaml b/.k8s/emptydir-volume/database/configmap.yaml index 05e0a37..774403f 100644 --- a/.k8s/emptydir-volume/database/configmap.yaml +++ b/.k8s/emptydir-volume/database/configmap.yaml @@ -4,4 +4,4 @@ metadata: name: devcamper-db-configmap namespace: devcamper-namespace data: - mongodb_db_name: 'devcamper-db' + mongodb_db_name: devcamper-db diff --git a/.k8s/emptydir-volume/database/deployment.yaml b/.k8s/emptydir-volume/database/deployment.yaml index 4f13e93..155462c 100644 --- a/.k8s/emptydir-volume/database/deployment.yaml +++ b/.k8s/emptydir-volume/database/deployment.yaml @@ -17,7 +17,7 @@ spec: spec: containers: - name: devcamper-db-container - image: mongo:4.4 + image: mongo ports: - containerPort: 27017 env: @@ -44,8 +44,8 @@ spec: memory: '1Gi' cpu: '1' volumeMounts: - - name: mongo-volume + - name: mongodb-volume mountPath: /data/db volumes: - - name: mongo-volume + - name: mongodb-volume emptyDir: {} diff --git a/.k8s/emptydir-volume/database/install.sh b/.k8s/emptydir-volume/database/install.sh index b1aa41b..f2cd6a6 100644 --- a/.k8s/emptydir-volume/database/install.sh +++ b/.k8s/emptydir-volume/database/install.sh @@ -2,6 +2,6 @@ kubectl apply -f configmap.yaml kubectl apply -f secret.yaml kubectl apply -f deployment.yaml -kubectl apply -f service-nodeport.yaml -kubectl apply -f service-clusterip.yaml +kubectl apply -f service.yaml + diff --git a/.k8s/emptydir-volume/database/secret.yaml b/.k8s/emptydir-volume/database/secret.yaml index 9dc04fb..8b8de8a 100644 --- a/.k8s/emptydir-volume/database/secret.yaml +++ b/.k8s/emptydir-volume/database/secret.yaml @@ -4,5 +4,5 @@ metadata: name: devcamper-db-secret namespace: devcamper-namespace data: - mongodb_username: 'YWRtaW4=' # base64 encoded string for 'admin' - mongodb_password: 'cGFzc3dvcmQ=' # base64 encoded string for 'password' + mongodb_username: 'YWRtaW4=' + mongodb_password: 'cGFzc3dvcmQ=' diff --git a/.k8s/emptydir-volume/database/service-nodeport.yaml b/.k8s/emptydir-volume/database/service-nodeport.yaml deleted file mode 100644 index 938ee4e..0000000 --- a/.k8s/emptydir-volume/database/service-nodeport.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: devcamper-db-nodeport-service - namespace: devcamper-namespace -spec: - type: NodePort - selector: - app: devcamper-db - ports: - - protocol: TCP - port: 27017 - targetPort: 27017 - nodePort: 32017 diff --git a/.k8s/emptydir-volume/database/service-clusterip.yaml b/.k8s/emptydir-volume/database/service.yaml similarity index 83% rename from .k8s/emptydir-volume/database/service-clusterip.yaml rename to .k8s/emptydir-volume/database/service.yaml index a49704d..6d7883c 100644 --- a/.k8s/emptydir-volume/database/service-clusterip.yaml +++ b/.k8s/emptydir-volume/database/service.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: devcamper-db-clusterip-service + name: devcamper-db-service namespace: devcamper-namespace spec: type: ClusterIP diff --git a/.k8s/emptydir-volume/database/uninstall.sh b/.k8s/emptydir-volume/database/uninstall.sh index c408ac9..398ae0c 100644 --- a/.k8s/emptydir-volume/database/uninstall.sh +++ b/.k8s/emptydir-volume/database/uninstall.sh @@ -2,5 +2,5 @@ kubectl delete -f configmap.yaml kubectl delete -f secret.yaml kubectl delete -f deployment.yaml -kubectl delete -f service-nodeport.yaml -kubectl delete -f service-clusterip.yaml +kubectl delete -f service.yaml + diff --git a/.k8s/emptydir-volume/install.sh b/.k8s/emptydir-volume/install.sh index a264e08..153a8d9 100644 --- a/.k8s/emptydir-volume/install.sh +++ b/.k8s/emptydir-volume/install.sh @@ -1,11 +1,13 @@ #!/bin/bash -# Function to run install script in a directory +# Function to run install scripts in specified directories run_install() { local dir=$1 - cd "$dir" || { echo "Failed to change directory to $dir"; exit 1; } + echo -e "\033[1;34m==================== Installing $dir ====================\033[0m" + cd "$dir" || { echo -e "\033[1;31mFailed to change directory to $dir\033[0m"; exit 1; } bash ./install.sh - cd - > /dev/null || { echo "Failed to return to previous directory"; exit 1; } + cd - > /dev/null || { echo -e "\033[1;31mFailed to return to previous directory\033[0m"; exit 1; } + echo -e "\033[1;34m==================== Finished $dir ====================\033[0m" } # Set trap to ensure we return to the original directory on exit @@ -16,3 +18,4 @@ run_install namespace run_install database run_install webapi run_install webapp +run_install network \ No newline at end of file diff --git a/.k8s/emptydir-volume/network/ingress.yaml b/.k8s/emptydir-volume/network/ingress.yaml new file mode 100644 index 0000000..661c3c4 --- /dev/null +++ b/.k8s/emptydir-volume/network/ingress.yaml @@ -0,0 +1,30 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: devcamper-ingress + namespace: devcamper-namespace + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx + rules: + - host: devcamper.webapp + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: devcamper-webapp-service + port: + number: 80 + - host: devcamper.webapi + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: devcamper-webapi-service + port: + number: 80 diff --git a/.k8s/emptydir-volume/network/install.sh b/.k8s/emptydir-volume/network/install.sh new file mode 100644 index 0000000..6ab0a3e --- /dev/null +++ b/.k8s/emptydir-volume/network/install.sh @@ -0,0 +1,4 @@ +#!bin/bash +# Install an NGINX Ingress Controller +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml +kubectl apply -f ingress.yaml \ No newline at end of file diff --git a/.k8s/emptydir-volume/network/uninstall.sh b/.k8s/emptydir-volume/network/uninstall.sh new file mode 100644 index 0000000..84d9ef5 --- /dev/null +++ b/.k8s/emptydir-volume/network/uninstall.sh @@ -0,0 +1,2 @@ +#!bin/bash +kubectl delete -f ingress.yaml \ No newline at end of file diff --git a/.k8s/emptydir-volume/uninstall.sh b/.k8s/emptydir-volume/uninstall.sh index 3dd7216..69e7345 100644 --- a/.k8s/emptydir-volume/uninstall.sh +++ b/.k8s/emptydir-volume/uninstall.sh @@ -3,9 +3,11 @@ # Function to run uninstall script in a directory run_uninstall() { local dir=$1 - cd "$dir" || { echo "Failed to change directory to $dir"; exit 1; } + echo -e "\033[1;34m==================== Uninstalling $dir ====================\033[0m" + cd "$dir" || { echo -e "\033[1;31mFailed to change directory to $dir\033[0m"; exit 1; } bash ./uninstall.sh - cd - > /dev/null || { echo "Failed to return to previous directory"; exit 1; } + cd - > /dev/null || { echo -e "\033[1;31mFailed to return to previous directory\033[0m"; exit 1; } + echo -e "\033[1;34m==================== Finished $dir ====================\033[0m" } # Set trap to ensure we return to the original directory on exit @@ -15,4 +17,5 @@ trap 'cd - > /dev/null' EXIT run_uninstall database run_uninstall webapi run_uninstall webapp -run_uninstall namespace +run_uninstall network +run_uninstall namespace \ No newline at end of file diff --git a/.k8s/emptydir-volume/webapi/configmap.yaml b/.k8s/emptydir-volume/webapi/configmap.yaml index fba66ae..b0f3f98 100644 --- a/.k8s/emptydir-volume/webapi/configmap.yaml +++ b/.k8s/emptydir-volume/webapi/configmap.yaml @@ -4,7 +4,7 @@ metadata: name: devcamper-webapi-configmap namespace: devcamper-namespace data: - mongodb_host: 'devcamper-db-clusterip-service' + mongodb_host: 'devcamper-db-service' mongodb_port: '27017' mongodb_db_name: 'devcamper-db' mongodb_db_params: 'authSource=admin' diff --git a/.k8s/emptydir-volume/webapi/install.sh b/.k8s/emptydir-volume/webapi/install.sh index 8d37872..6e708a3 100644 --- a/.k8s/emptydir-volume/webapi/install.sh +++ b/.k8s/emptydir-volume/webapi/install.sh @@ -2,6 +2,5 @@ kubectl apply -f configmap.yaml kubectl apply -f secret.yaml kubectl apply -f deployment.yaml -kubectl apply -f service-nodeport.yaml -kubectl apply -f service-loadbalancer.yaml +kubectl apply -f service.yaml diff --git a/.k8s/emptydir-volume/webapi/service-loadbalancer.yaml b/.k8s/emptydir-volume/webapi/service-loadbalancer.yaml deleted file mode 100644 index 6d52031..0000000 --- a/.k8s/emptydir-volume/webapi/service-loadbalancer.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: devcamper-webapi-loadbalancer-service - namespace: devcamper-namespace -spec: - type: LoadBalancer - ports: - - protocol: TCP - port: 8081 - targetPort: 5000 - selector: - app: devcamper-webapi diff --git a/.k8s/emptydir-volume/webapi/service-nodeport.yaml b/.k8s/emptydir-volume/webapi/service.yaml similarity index 69% rename from .k8s/emptydir-volume/webapi/service-nodeport.yaml rename to .k8s/emptydir-volume/webapi/service.yaml index 32683c4..6bb8d9e 100644 --- a/.k8s/emptydir-volume/webapi/service-nodeport.yaml +++ b/.k8s/emptydir-volume/webapi/service.yaml @@ -1,14 +1,12 @@ apiVersion: v1 kind: Service metadata: - name: devcamper-webapi-nodeport-service + name: devcamper-webapi-service namespace: devcamper-namespace spec: - type: NodePort ports: - protocol: TCP port: 80 targetPort: 5000 - nodePort: 32002 selector: app: devcamper-webapi diff --git a/.k8s/emptydir-volume/webapi/uninstall.sh b/.k8s/emptydir-volume/webapi/uninstall.sh index a67d1e9..40249bd 100644 --- a/.k8s/emptydir-volume/webapi/uninstall.sh +++ b/.k8s/emptydir-volume/webapi/uninstall.sh @@ -2,5 +2,4 @@ kubectl delete -f configmap.yaml kubectl delete -f secret.yaml kubectl delete -f deployment.yaml -kubectl delete -f service-nodeport.yaml -kubectl delete -f service-loadbalancer.yaml \ No newline at end of file +kubectl delete -f service.yaml diff --git a/.k8s/emptydir-volume/webapp/configmap.yaml b/.k8s/emptydir-volume/webapp/configmap.yaml index d886bde..1d23696 100644 --- a/.k8s/emptydir-volume/webapp/configmap.yaml +++ b/.k8s/emptydir-volume/webapp/configmap.yaml @@ -4,4 +4,4 @@ metadata: name: devcamper-webapp-configmap namespace: devcamper-namespace data: - react_app_devcamper_base_api_uri: 'http://devcamper-webapi-nodeport-service.devcamper-namespace.svc.cluster.local:32002' + react_app_devcamper_base_api_uri: 'http://devcamper.webapi' diff --git a/.k8s/emptydir-volume/webapp/install.sh b/.k8s/emptydir-volume/webapp/install.sh index 50777e5..13d4082 100644 --- a/.k8s/emptydir-volume/webapp/install.sh +++ b/.k8s/emptydir-volume/webapp/install.sh @@ -1,5 +1,4 @@ #!bin/bash kubectl apply -f configmap.yaml kubectl apply -f deployment.yaml -kubectl apply -f service-nodeport.yaml -kubectl apply -f service-loadbalancer.yaml \ No newline at end of file +kubectl apply -f service.yaml diff --git a/.k8s/emptydir-volume/webapp/service-loadbalancer.yaml b/.k8s/emptydir-volume/webapp/service-loadbalancer.yaml deleted file mode 100644 index aed19d0..0000000 --- a/.k8s/emptydir-volume/webapp/service-loadbalancer.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: devcamper-webapp-loadbalancer-service - namespace: devcamper-namespace -spec: - type: LoadBalancer - ports: - - protocol: TCP - port: 8080 - targetPort: 3000 - selector: - app: devcamper-webapp diff --git a/.k8s/emptydir-volume/webapp/service-nodeport.yaml b/.k8s/emptydir-volume/webapp/service.yaml similarity index 69% rename from .k8s/emptydir-volume/webapp/service-nodeport.yaml rename to .k8s/emptydir-volume/webapp/service.yaml index ca65459..0e8e168 100644 --- a/.k8s/emptydir-volume/webapp/service-nodeport.yaml +++ b/.k8s/emptydir-volume/webapp/service.yaml @@ -1,14 +1,12 @@ apiVersion: v1 kind: Service metadata: - name: devcamper-webapp-nodeport-service + name: devcamper-webapp-service namespace: devcamper-namespace spec: - type: NodePort ports: - protocol: TCP port: 80 targetPort: 3000 - nodePort: 32001 selector: app: devcamper-webapp diff --git a/.k8s/emptydir-volume/webapp/uninstall.sh b/.k8s/emptydir-volume/webapp/uninstall.sh index db553ac..1a6e510 100644 --- a/.k8s/emptydir-volume/webapp/uninstall.sh +++ b/.k8s/emptydir-volume/webapp/uninstall.sh @@ -1,5 +1,4 @@ #!bin/bash kubectl delete -f configmap.yaml kubectl delete -f deployment.yaml -kubectl delete -f service-nodeport.yaml -kubectl delete -f service-loadbalancer.yaml \ No newline at end of file +kubectl delete -f service.yaml