Question : Some of the Nautilus team 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 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 tag i.e nginx:latest and name it as nginx-deployment. App labels should be app: nginx-app and type: front-end. The container should be named as nginx-container; also make sure replica counts are 3.
Also create a service named nginx-service and type NodePort. The targetPort should be 80 and nodePort should be 30011.
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
Please Note :- Perform the below commands based on your question server, user name & other details might differ . So please read task carefully before executing. All the Best 👍
Solution:
1. At first check existing deployment and pods running status
kubectl get namespace
kubectl get pods
2. Create YAML file with all the parameters, you can copy form GitLab
https://gitlab.com/nb-tech-support/devops.git
( Refer Below Video for more clarity )
thor@jump_host /$ vi /tmp/nginx.yml thor@jump_host /$ cat /tmp/nginx.yml apiVersion: v1 kind: Service metadata: name:
nginx-service spec: type: NodePort selector: app: nginx-app type: front-end ports: - port: 80 targetPort: 80 nodePort:
30011 --- apiVersion: apps/v1 kind: Deployment metadata: name:
nginx-deployment labels: app: nginx-app type: front-end spec: replicas: 3 selector: matchLabels: app: nginx-app type:
front-end template: metadata: labels: app:
nginx-app type:
front-end spec: containers: - name:
nginx-container image:
nginx:latest thor@jump_host /$ |
3. Run below command to create pod
thor@jump_host /$ kubectl create -f /tmp/nginx.yml service/nginx-service created deployment/nginx-deployment created thor@jump_host /$ |
thor@jump_host /$ kubectl get pods NAME
READY STATUS RESTARTS AGE nginx-deployment-56cdb5d774-49rqs
1/1 Running 0
34s nginx-deployment-56cdb5d774-6q8b2
1/1 Running 0
34s nginx-deployment-56cdb5d774-nfwfp
1/1
Running 0 34s thor@jump_host /$ |
5. Validate the task by running below command
kubectl exec nginx-deployment-56cdb5d774-49rqs -- curl http://localhost
Happy Learning!!!!
please go through and share
your comments. Like and share the knowledge
4 Comments
Hi. Great Code! Although I have a doubt please: would it occur a syntax error if I put the same name in the Container as in the apps? For an instante, in your code, would it occur a syntax error if I put the name "nginx-app" in spite of "nginx-container"? Thanks a lot in advance for your comments on that. Best regards!
ReplyDeleteThis comment has been removed by the author.
DeleteThanks for your kind words. Please feel free to reach for any queries / doubt you have. Regarding your doubt, you can change any name, please make sure you change it wherever is applicable. Still have concern the ping me for online support chat. All the Best . Keep Learning
DeleteHi!
ReplyDeleteThanks for the response!
I understood that I can change any name.
But I have a more specific question please.
I would like to know if it is possible to have the same names in the apps and in the Container.
For an instance, in your code, if you put the Container name as "nginx-app" (the same name of the apps declared together in your code) would it function correctly? Or may it occur an error?
I have this doubt because for some API types, such as ReplicaSets, the 2 instance label selectors must not overlap in ONE namespace, or the controller may see these as conflicting instructions and not be able to determine how many replicas should be present.
So it is why I am asking you that.
Thanks a lot in advance for your help!
Kind regards,
Sergio Guimarães Villaça