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.
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
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
Step 3: Deploy the Node.js Deployment
Apply the deployment to your Kubernetes cluster:
kubectl apply -f node-deployment.yaml
Step 4: Deploy the Node.js Service
Apply the service configuration:
kubectl apply -f node-service.yaml
Step 5: Verify the Deployment
Check if the deployment was created successfully:
kubectl get deployments
Step 6: Verify the Service
Check if the service is running:
kubectl get services
Step 7: Check the Pod Status
Verify that both pods are running:
kubectl get pods -l app=node-app




Top comments (0)