Steps to Deploy the Application in Kubernetes and Dockers

Step 1: Dockerization

Prepare the application for Dockerization by creating a Dockerfile. This file includes instructions for building a Docker image.

Dockerfile Example:

FROM node:14
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]

Step 2: Build Docker Image

docker build -t your-image-name:tag .

Step 3: Push to Docker Hub

docker login
docker push your-image-name:tag

Step 4: Kubernetes Deployment

Prepare Kubernetes deployment using imperative commands.

Deployment Example:

kubectl create deployment your-deployment --image=your-image-name:tag --replicas=3

Service Example:

kubectl expose deployment your-deployment --type=LoadBalancer --port=80

Additional Steps:

  1. Check the status of the deployment:
  2. kubectl get deployments
  3. Check the status of the pods:
  4. kubectl get pods
  5. Check the status of the service:
  6. kubectl get services

Scale Deployment:

Scale the deployment to 5 replicas:

kubectl scale deployment your-deployment --replicas=5

Delete Deployment:

Delete the deployment and associated resources:

kubectl delete deployment your-deployment

Step 6: Scale Deployment

Scale the deployment to a specified number of replicas.

Scale Deployment Example:

kubectl scale deployment your-deployment --replicas=5

Step 7: Monitor and Troubleshoot

Monitor the deployment using Kubernetes dashboard or command-line tools. Review logs and troubleshoot any issues as needed.

Check Pods:

kubectl get pods

Check Services:

kubectl get services

View Logs:

kubectl logs pod-name

Step 6: Verify Deployment

After deploying your application to Kubernetes, it's crucial to verify its functionality and ensure a successful deployment. Follow these steps to perform verification:

  1. Accessing the Deployed Application:
    • Identify the External IP or DNS of your Kubernetes service. This information is crucial for accessing your application.
    • Run the following command to get the external IP (for a LoadBalancer type service) or NodePort (for a NodePort type service):
      kubectl get services
    • Once you have the External IP or NodePort, open a web browser and enter the following URL:
      http://external-ip-or-node-port
  2. Verifying Functionality:
    • Ensure that the application loads successfully in the web browser.
    • Perform basic interactions with the application to verify core functionality.
    • Check console logs or developer tools in the browser for any errors or warnings.
  3. Checking Logs:
    • Use the following command to view the logs of your application's pods:
      kubectl logs -l app = your-app
    • Inspect the logs for any error messages, warnings, or other relevant information that might indicate issues with the deployment.

By following these steps, you can ensure that your application is not only deployed successfully but also functioning as expected. Address any issues or errors encountered during this verification process to maintain a reliable and robust deployment.

Back