This project includes the following Kubernetes manifest files:
mongo-config.yaml- This file defines a ConfigMap for MongoDB, which provides configuration settings for the database. Themongo-urlkey in the ConfigMap stores the MongoDB service name (mongo-service), allowing other components in the cluster to reference it easily.mongo-secret.yaml- This file defines a Secret that stores sensitive credentials for MongoDB, includingmongo-userandmongo-password. These credentials are base64 encoded and referenced by the MongoDB and web application deployments for secure authentication.mongo.yaml- This file contains the deployment and service configuration for MongoDB:- Deployment: Creates a MongoDB pod using the
mongo:5.0image and sets environment variables from the Secret. - Service: Exposes MongoDB within the cluster using a service named
mongo-service.
- Deployment: Creates a MongoDB pod using the
webapp.yaml- This file contains the deployment and service configuration for the web application:- Deployment: Creates a web application pod using the
nanajanashia/k8s-demo-app:v1.0image and connects to MongoDB using credentials from the Secret and configuration from the ConfigMap. - Service: Exposes the web application using a
NodePortservice (webapp-service), making it accessible on port30100.
- Deployment: Creates a web application pod using the
selector:
matchLabels:
app: mongo- Ensures the Deployment manages only the Pods with the label
app: mongo.
selector:
app: mongo- Ensures the Service routes traffic only to the Pods labeled
app: mongo.
To deploy the MongoDB and web application components, use the following commands:
-
Apply the MongoDB configuration:
kubectl apply -f mongo-config.yaml
Creates a ConfigMap named
mongo-config. -
Apply the MongoDB secrets:
kubectl apply -f mongo-secret.yaml
Creates a Secret named
mongo-secret. -
Deploy MongoDB:
kubectl apply -f mongo.yaml
Creates MongoDB deployment and service (
mongo-deploymentandmongo-service). -
Deploy the web application:
kubectl apply -f webapp.yaml
Creates web application deployment and service (
webapp-deploymentandwebapp-service).
minikube start --vm-driver=hyperkit
minikube statusminikube ipkubectl get node
kubectl get pod
kubectl get svc
kubectl get allkubectl get pod -o wide
kubectl get node -o widekubectl describe svc {svc-name}
kubectl describe pod {pod-name}kubectl logs {pod-name}minikube stop- Start Minikube and ensure it's running properly.
- Deploy the MongoDB and web application manifests using
kubectl apply -f {filename}. - Verify the deployments and services using the commands provided above.
- Check logs and debug if necessary.
- Stop Minikube when finished.
This project is inspired by the Kubernetes deployment guide from Kubernetes in 1 Hour.
This project is open-source and available under the MIT License.
