initial commit

This commit is contained in:
2024-06-07 22:37:18 -04:00
commit 207a38f1e3
41 changed files with 59014 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
# https://kubernetes.io/docs/concepts/configuration/configmap/
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-config
data:
mongo-url: mongo-service
+9
View File
@@ -0,0 +1,9 @@
# https://kubernetes.io/docs/concepts/configuration/secret/
apiVersion: v1
kind: Secret
metadata:
name: mongo-secret
type: Opaque
data:
mongo-user: bW9uZ291c2Vy
mongo-password: bW9uZ29wYXNzd29yZA==
+47
View File
@@ -0,0 +1,47 @@
# deployement and service for mongodb
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1
kind: Deployment
metadata:
name: mgongo-deployment
labels:
app: mgongo
spec: # deployement-specific
replicas: 1
selector:
matchLabels:
app: mgongo
template: # deployement for the pods
metadata:
labels:
app: mgongo
spec:
containers: # https://hub.docker.com/_/mongo
- name: mongodb
image: mongo:5.0
ports:
- containerPort: 27017
env: # sameple values for the demo webserver
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef: # get from secrets
name: mongo-secret
key: mongo-user
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef: # get from secrets
name: mongo-secret
key: mongo-password
--- # "new file"
# https://kubernetes.io/docs/concepts/services-networking/service/
apiVersion: v1
kind: Service
metadata:
name: mongo-service
spec:
selector:
app: mongo
ports:
- protocol: TCP
port: 27017
targetPort: 27017
+33
View File
@@ -0,0 +1,33 @@
## Initial Steps (readying your app)
*Note: I assume you already have a minikube running*
1. check if you have any pods running with `kubectl get pod` and stop them if so
2. create external configurations
- kubectl apply -f mongo-config.yaml
- kubectl apply -f mongo-secret.yaml
★ the -f is for file
3. create connection for the database
- kubectl apply -f mongo.yaml
4. deploy the web app
- kubectl apply -f webapp.yaml
## Kubectl
1. check your pods using `kubectl get all`
2. check your configmap using `kubectl get configmap`
3. check your secrets using `kubectl get secret`
- you can use `kubectl get [component_name]` to get some data for any component or run `kubectl get --help` for help with the `get` subcommand
- you can use `kubectl describe service [service_name]` to get a description of the service
- you can use `kubectl logs [pod_name]` to get the logs for that pod
## Accessing the Application Externally
In our case from the browser
1. use `kubectl get svc` to get the service
2. get the `nodPort`'s ip using `minikube ip`
★ you can access more data using `kubectl get node -o wide`
3. access the ip using the corresponding IP address : port
+54
View File
@@ -0,0 +1,54 @@
# deployement and service for mongodb
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: webapp
spec: # deployement-specific
replicas: 1
selector:
matchLabels:
app: webapp
template: # deployement for the pods
metadata:
labels:
app: webapp
spec:
containers: # https://hub.docker.com/_/mongo
- name: webapp
image: nanajanashia/k8s-demo-app:v1.0 # demo web app
ports:
- containerPort: 3000
env: #add demo information
- name: USER_NAME
valueFrom:
secretKeyRef: # get from secrets
name: mongo-secret
key: mongo-user
- name: USER_PWD
valueFrom:
secretKeyRef: # get from secrets
name: mongo-secret
key: mongo-password
- name: DB_URL
valueFrom:
configMapKeyRef: # get from configMap
name: mongo-config
key: mongo-url
--- # "new file"
# https://kubernetes.io/docs/concepts/services-networking/service/
apiVersion: v1
kind: Service
metadata:
name: webapp-service
spec:
type: NodePort # external service port type
selector:
app: webapp
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30100 # see https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport for ranges