Skip to content

Commit

Permalink
Update k8s YAMLs
Browse files Browse the repository at this point in the history
  • Loading branch information
prasadhonrao committed Oct 24, 2024
1 parent 1cc4811 commit 0adf65a
Showing 22 changed files with 67 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .k8s/emptydir-volume/database/configmap.yaml
Original file line number Diff line number Diff line change
@@ -4,4 +4,4 @@ metadata:
name: devcamper-db-configmap
namespace: devcamper-namespace
data:
mongodb_db_name: 'devcamper-db'
mongodb_db_name: devcamper-db
6 changes: 3 additions & 3 deletions .k8s/emptydir-volume/database/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
4 changes: 2 additions & 2 deletions .k8s/emptydir-volume/database/install.sh
Original file line number Diff line number Diff line change
@@ -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


4 changes: 2 additions & 2 deletions .k8s/emptydir-volume/database/secret.yaml
Original file line number Diff line number Diff line change
@@ -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='
14 changes: 0 additions & 14 deletions .k8s/emptydir-volume/database/service-nodeport.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Service
metadata:
name: devcamper-db-clusterip-service
name: devcamper-db-service
namespace: devcamper-namespace
spec:
type: ClusterIP
4 changes: 2 additions & 2 deletions .k8s/emptydir-volume/database/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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

9 changes: 6 additions & 3 deletions .k8s/emptydir-volume/install.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions .k8s/emptydir-volume/network/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .k8s/emptydir-volume/network/install.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .k8s/emptydir-volume/network/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!bin/bash
kubectl delete -f ingress.yaml
9 changes: 6 additions & 3 deletions .k8s/emptydir-volume/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .k8s/emptydir-volume/webapi/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 1 addition & 2 deletions .k8s/emptydir-volume/webapi/install.sh
Original file line number Diff line number Diff line change
@@ -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

13 changes: 0 additions & 13 deletions .k8s/emptydir-volume/webapi/service-loadbalancer.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions .k8s/emptydir-volume/webapi/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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
kubectl delete -f service.yaml
2 changes: 1 addition & 1 deletion .k8s/emptydir-volume/webapp/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 1 addition & 2 deletions .k8s/emptydir-volume/webapp/install.sh
Original file line number Diff line number Diff line change
@@ -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
kubectl apply -f service.yaml
13 changes: 0 additions & 13 deletions .k8s/emptydir-volume/webapp/service-loadbalancer.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions .k8s/emptydir-volume/webapp/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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
kubectl delete -f service.yaml

0 comments on commit 0adf65a

Please sign in to comment.