Question : A new java-based application is ready to be deployed on a Kubernetes cluster. The development team had a meeting with the DevOps team share requirements and application scope. The team is ready to setup an application stack for it under their existing cluster. Below you can find the details for this:
Create a namespace named tomcat-namespace-xfusion.
Create a deployment for tomcat app which should be named tomcat-deployment-xfusion under the same namespace you created. Replicas count should be 1, the container should be named as tomcat-container-xfusion, its image should be gcr.io/kodekloud/centos-ssh-enabled:tomcat and its container port should be 8080.
Create a service for tomcat app which should be named as tomcat-service-xfusion under the same namespace you created. Service type should be NodePort. Port's protocol should be TCP, port should be 80, targetPort should be 8080 and nodePort should be 32227.
Before clicking on Finish button please make sure the application is up and running.
You can use any labels as per your choice.
Note: The kubectl 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 kubectl utility configure and working from jump server, run below commands
kubectl get namespace
kubectl get pods
2. Create new namespace
thor@jump_host
/$ kubectl create namespace tomcat-namespace-xfusion namespace/tomcat-namespace-xfusion created thor@jump_host /$ kubectl get namespace NAME STATUS AGE default Active 2m1s kube-node-lease Active 2m6s kube-public Active 2m6s kube-system Active 2m6s tomcat-namespace-xfusion Active 36s |
https://gitlab.com/nb-tech-support/devops.git
( Refer Below Video for more clarity )
apiVersion: v1 kind: Service metadata: name: tomcat-service-xfusion namespace: tomcat-namespace-xfusion spec: type: NodePort selector: app: tomcat ports: - port: 80 protocol: TCP targetPort: 8080 nodePort: 32227 --- apiVersion: apps/v1 kind: Deployment metadata: name: tomcat-deployment-xfusion namespace: tomcat-namespace-xfusion spec: replicas: 1 selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat-container-xfusion image:
gcr.io/kodekloud/centos-ssh-enabled:tomcat ports: - containerPort: 8080 |
|
4. Run below command to create pod
thor@jump_host
/$ kubectl create -f /tmp/tomcat.yaml service/tomcat-service-xfusion
created deployment.apps/tomcat-deployment-xfusion
created |
thor@jump_host
/$ kubectl get deploy -n tomcat-namespace-xfusion NAME READY UP-TO-DATE AVAILABLE
AGE tomcat-deployment-xfusion 1/1
1 1 91s thor@jump_host
/$ thor@jump_host
/$ kubectl get pods -n tomcat-namespace-xfusion NAME READY STATUS RESTARTS AGE tomcat-deployment-xfusion-654c5b77ff-x8q7h 0/1
ContainerCreating 0 18s thor@jump_host
/$ |
6. Validate the task by running below command
thor@jump_host
/$ % Total
% Received % Xferd Average
Speed Time Time
Time Current Dload Upload
Total Spent Left
Speed 100 471
100 471 0
0 4528 0 --:--:-- --:--:-- --:--:-- 4528 <!DOCTYPE
html> <!-- To change this
license header, choose License Headers in Project Properties. To change this
template file, choose Tools | Templates and open the
template in the editor. --> <html> <head>
<title>SampleWebApp</title> <meta
charset="UTF-8"> <meta name="viewport" content="width=device-width,
initial-scale=1.0"> </head> <body> <h2>Welcome to xFusionCorp
Industries!</h2> <br> </body> </html> thor@jump_host
/$ |
Happy Learning!!!!
0 Comments