[website-link] "https://e-commerce-by-mahesh.vercel.app/"
- Here i tried to deploy E commerce application on K8S
- i created and pushed docker image on docker hub
- i made k8s yaml file to setup containers on it
To use Kubernetes (K8s) with your Node.js application that you've Dockerized, you'll follow these general steps:
Create Kubernetes manifests in YAML format that describe your application's deployment, service, and optionally an Ingress (if you want to expose your application externally).
Here's a basic example:
deployment.yaml - Defines how your application should be deployed:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-node-app
spec:
replicas: 1
selector:
matchLabels:
app: my-node-app
template:
metadata:
labels:
app: my-node-app
spec:
containers:
- name: my-node-app
image: your-docker-registry/your-node-app-image:tag
ports:
- containerPort: 8000Replace your-docker-registry/your-node-app-image:tag with the actual path to your Docker image (e.g., myregistry/my-node-app:latest).
service.yaml - Defines how clients can access your application:
apiVersion: v1
kind: Service
metadata:
name: my-node-app
spec:
selector:
app: my-node-app
ports:
- protocol: TCP
port: 8000
targetPort: 8000
type: ClusterIPThis Service will create an internal IP address that other Kubernetes pods can use to access your application.
If you want to expose your application to the outside world, you can use an Ingress resource. Here's a basic example:
ingress.yaml - Defines how external traffic will reach your application:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-node-app-ingress
spec:
rules:
- host: your.domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-node-app
port:
number: 8000Replace your.domain.com with your actual domain name.
Once you have your Kubernetes manifests ready:
-
Apply Manifests: Use
kubectl applyto deploy your application to Kubernetes:kubectl apply -f deployment.yaml kubectl apply -f service.yaml kubectl apply -f ingress.yaml # If using Ingress -
Verify Deployment: Check the deployment status:
kubectl get deployments
Ensure that the deployment has
1/1replicas available. -
Verify Service: Check the service and get its ClusterIP:
kubectl get services
Verify that your service is running and note its ClusterIP.
-
Verify Ingress (Optional): If you used Ingress, verify that the Ingress resource is created and note the external IP.
-
Internal Access: If you only need internal access within the Kubernetes cluster, use the ClusterIP of your service to access your application from other pods.
-
External Access: If you used an Ingress resource, you can access your application using the configured host (
your.domain.comin the example) via the external IP provided by your cloud provider.
-
Scaling: You can scale your application by adjusting the
replicasfield in your deployment.yaml file and reapplying it usingkubectl apply -f deployment.yaml. -
Updating: To update your application, build a new Docker image with your changes, push it to your Docker registry, update the image tag in your deployment.yaml file, and apply the changes with
kubectl apply -f deployment.yaml.
- Kubernetes provides many more features like PersistentVolumes, Secrets, ConfigMaps, and more. Explore the Kubernetes documentation and tutorials to further enhance and secure your application.
By following these steps, you can effectively deploy and manage your Dockerized Node.js application using Kubernetes (K8s). If you have specific questions or need further clarification on any part of this process, feel free to ask!
Visualization:
┌─────────────────────────┐
│ Deployment │
│ (frontend-deployment) │
│ │
│ ┌───────────────────┐ │
│ │ Selector │ │
│ │ (matchLabels) │ │
│ │ app: frontend │ │
│ └───────────────────┘ │
│ │
│ ┌───────────────────┐ │
│ │ Pod Template │ │
│ │ (template) │ │
│ │ ┌───────────────┐ │
│ │ │ Labels │ │
│ │ │ app: frontend│ │
│ │ └───────────────┘ │
│ │ ┌───────────────┐ │
│ │ │ Containers │ │
│ │ │ ┌───────────┐ │
│ │ │ │ Name │ │
│ │ │ │mypagecontainer│ │
│ │ │ │ Image │ │
│ │ │ │maheshravaji/mylandingpageweb:latest│ │
│ │ │ │ Ports │ │
│ │ │ │ ┌───────┐│ │
│ │ │ │ │ 8000 ││ │
│ │ │ │ └───────┘│ │
│ │ │ └───────────┘ │
│ │ └───────────────┘ │
│ └───────────────────┘ │
└─────────────────────────┘
┌─────────────────────────┐
│ Service │
│ (my-service) │
│ │
│ ┌───────────────────┐ │
│ │ Selector │ │
│ │ (matchLabels) │ │
│ │ app: frontend │ │
│ └───────────────────┘ │
│ │
│ ┌───────────────────┐ │
│ │ Ports │ │
│ │ ┌─────────────┐ │ │
│ │ │ port: 80 │ │ │
│ │ │ targetPort: 8000│ │ │
│ │ └─────────────┘ │ │
│ └───────────────────┘ │
└─────────────────────────┘
Extra Point ⏬
+-----------------------------------------------------------------+
| Kubernetes Cluster |
| |
| +---------------------+ +---------------------+ |
| | dev-namespace | | prod-namespace | |
| | | | | |
| | +----------------+ | | +----------------+ | |
| | | Frontend Pod | | | | Frontend Pod | | |
| | | +-----------+ | | | | +-----------+ | | |
| | | | Container | | | | | | Container | | | |
| | | +-----------+ | | | | +-----------+ | | |
| | +----------------+ | | +----------------+ | |
| | | | | |
| | +----------------+ | | +----------------+ | |
| | | Backend Pod | | | | Backend Pod | | |
| | | +-----------+ | | | | +-----------+ | | |
| | | | Container | | | | | | Container | | | |
| | | +-----------+ | | | | +-----------+ | | |
| | +----------------+ | | +----------------+ | |
| | | | | |
| | +----------------+ | | +----------------+ | |
| | | Database Pod | | | | Database Pod | | |
| | | +-----------+ | | | | +-----------+ | | |
| | | | Container | | | | | | Container | | | |
| | | +-----------+ | | | | +-----------+ | | |
| | +----------------+ | | +----------------+ | |
| | | | | |
| | +----------------+ | | +----------------+ | |
| | | Redis Pod | | | | Redis Pod | | |
| | | +-----------+ | | | | +-----------+ | | |
| | | | Container | | | | | | Container | | | |
| | | +-----------+ | | | | +-----------+ | | |
| | +----------------+ | | +----------------+ | |
| +---------------------+ +---------------------+ |
+-----------------------------------------------------------------+
<<<<<<< HEAD
=======
55b9c067fe87802d5960e5c4ea128e717fbfef86
- unable to connect ( site Can't reached ) after pulling my docker image ---> but i solved finally ( how :)) - i messed in Service.yaml file of kubernetes that's it ... )
- i Know that yaml files of k8s are correctly typed still a am not able to access my application 'command :' http://<cluster_ip>:<nodeport_ip>
- ETC...
NOTE : Enjoy the journey, whether difficult or easy, for it's the making of a better you :) that's the person who i am :)