DEV Community

Cover image for 9.Deploy Node App on Kubernetes
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

9.Deploy Node App on Kubernetes

Lab Information

The Nautilus development team has completed development of one of the node applications, which they are planning to deploy on a Kubernetes cluster. They recently had a meeting with the DevOps team to share their requirements. Based on that, the DevOps team has listed out the exact requirements to deploy the app. Find below more details:

Create a deployment using gcr.io/kodekloud/centos-ssh-enabled:node image, replica count must be 2.

Create a service to expose this app, the service type must be NodePort, targetPort must be 8080 and nodePort should be 30012.

Make sure all the pods are in Running state after the deployment.

You can check the application by clicking on NodeApp button on top bar.
Enter fullscreen mode Exit fullscreen mode

You can use any labels as per your choice.

Note: The kubectl on jump_host has been configured to work with the kubernetes cluster.

Lab Solutions

Step 1: Create the Node.js Deployment YAML file

Create the deployment configuration file:

cat > node-deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-app-deployment
  labels:
    app: node-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app
    spec:
      containers:
      - name: node-container
        image: gcr.io/kodekloud/centos-ssh-enabled:node
        ports:
        - containerPort: 8080
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
EOF
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the Node.js Service YAML file

Create the service configuration file:

cat > node-service.yaml << EOF
apiVersion: v1
kind: Service
metadata:
  name: node-app-service
  labels:
    app: node-app
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30012
  selector:
    app: node-app
EOF
Enter fullscreen mode Exit fullscreen mode

Step 3: Deploy the Node.js Deployment

Apply the deployment to your Kubernetes cluster:

kubectl apply -f node-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Step 4: Deploy the Node.js Service

Apply the service configuration:

kubectl apply -f node-service.yaml
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify the Deployment

Check if the deployment was created successfully:

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

Step 6: Verify the Service

Check if the service is running:

kubectl get services
Enter fullscreen mode Exit fullscreen mode

Step 7: Check the Pod Status

Verify that both pods are running:

kubectl get pods -l app=node-app
Enter fullscreen mode Exit fullscreen mode

Step 8: Test the Application


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)