Our course you can check :- Udemy course
Ques:-
Developers are developing a static website and they want to deploy it on Kubernetes cluster. They want it to be highly available and scalable. Therefore, based on the requirements, the DevOps team has decided to create a deployment for it with multiple replicas. Below you can find more details about it:
Create a deployment using nginx image with latest tag only and remember to mention the tag i.e nginx:latest. Name it as nginx-deployment. The container should be named as nginx-container, also make sure replica counts are 3.
Create a NodePort type service named nginx-service. The nodePort should be 30011.
Ans:-
Here’s how you can create the Deployment and NodePort Service for your static website using the nginx:latest
image in a Kubernetes cluster.
raj@jumphost ~$ cat pod.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30011
raj@jumphost ~$ kubectl apply -f pod.yaml
deployment.apps/nginx-deployment created
service/nginx-service created
raj@jumphost ~$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 19s
raj@jumphost ~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-5b58668cfc-4tq5f 1/1 Running 0 26s
nginx-deployment-5b58668cfc-sls7t 1/1 Running 0 26s
nginx-deployment-5b58668cfc-w5pt6 1/1 Running 0 26s
raj@jumphost ~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service NodePort 10.96.37.48 <none> 80:30011/TCP 36s
Once deployed, your static website will be accessible via any node's IP on port 30011
.
No comments:
Post a Comment