Our course you can check :- Udemy course
Ques:-
A new java-based application is ready to be deployed on a Kubernetes cluster. The development team had a meeting with the DevOps team to share the 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-datacenter.
Create a deployment for tomcat app which should be named as tomcat-deployment-datacenter under the same namespace you created. Replica count should be 1, the container should be named as tomcat-container-datacenter, 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-datacenter under the same namespace you created. Service type should be NodePort and nodePort should be 32227.
You can use any labels as per your choice.
Ans:-
Here’s the complete Kubernetes YAML configuration to deploy your Java-based Tomcat application as per the provided requirements:
raj@jumphost ~$ cat pod.yaml
---
apiVersion: v1
kind: Namespace
metadata:
name: tomcat-namespace-datacenter
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment-datacenter
namespace: tomcat-namespace-datacenter
labels:
app: tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
containers:
- name: tomcat-container-datacenter
image: gcr.io/kodekloud/centos-ssh-enabled:tomcat
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tomcat-service-datacenter
namespace: tomcat-namespace-datacenter
spec:
type: NodePort
selector:
app: tomcat
ports:
- port: 8080
targetPort: 8080
nodePort: 32227
raj@jumphost ~$ kubectl apply -f pod.yaml
namespace/tomcat-namespace-datacenter created
deployment.apps/tomcat-deployment-datacenter created
service/tomcat-service-datacenter created
raj@jumphost ~$ kubectl get all -n tomcat-namespace-datacenter
NAME READY STATUS RESTARTS AGE
pod/tomcat-deployment-datacenter-6c696b4c7f-9qhdr 1/1 Running 0 36s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/tomcat-service-datacenter NodePort 10.96.33.73 <none> 8080:32227/TCP 36s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/tomcat-deployment-datacenter 1/1 1 1 36s
NAME DESIRED CURRENT READY AGE
replicaset.apps/tomcat-deployment-datacenter-6c696b4c7f 1 1 1 36s
raj@jumphost ~$
Then access the Tomcat app in your browser at:
http://<NodeIP>:32227
Replace <NodeIP>
with your Kubernetes node's external IP.
Learn how to deploy a Java-based Tomcat application on a Kubernetes cluster using real-world DevOps practices. In this hands-on tutorial, you'll walk through the complete process of setting up a dedicated namespace, deploying a Tomcat container, and exposing it via a NodePort service.
What You’ll Learn:
- Creating and managing Kubernetes namespaces
- Deploying a Tomcat application using a custom Docker image
- Configuring Kubernetes Deployments and Services
- Exposing applications using NodePort
- Accessing the Tomcat web interface from your browser
This course is ideal for DevOps engineers, system administrators, and developers looking to gain practical experience in deploying Java applications on Kubernetes.
No comments:
Post a Comment