Kubernetes makes it easy to deploy and manage containerized applications, but understanding its manifest files is crucial for effective orchestration. In this blog, we'll break down a Kubernetes manifest file that defines a Deployment and a Service for a Eureka Server instance.
Understanding the Manifest File
This YAML file consists of two key Kubernetes resources:
- Deployment: Defines how the Eureka Server container should be deployed.
- Service: Exposes the Eureka Server for external access.
Let's analyze each section in detail.
1. Deployment Configuration
The first part of the YAML file describes a Deployment, which ensures the Eureka Server container runs in a managed and scalable manner.
apiVersion: apps/v1
kind: Deployment
metadata:
name: eurekaserver-deployment
labels:
app: eurekaserver
-
apiVersion: apps/v1→ Specifies that this is a Deployment resource. -
kind: Deployment→ Defines this resource as a Deployment. -
metadata→ Contains identifying information.-
name: eurekaserver-deployment→ Names the deployment. -
labels: app: eurekaserver→ Labels help Kubernetes group and select resources.
-
Replica Configuration
spec:
replicas: 1
selector:
matchLabels:
app: eurekaserver
-
replicas: 1→ Defines the number of pod instances to run (here, just one). -
selector: matchLabels: app: eurekaserver→ Ensures this deployment manages pods with the labelapp: eurekaserver.
Pod Template Definition
template:
metadata:
labels:
app: eurekaserver
-
template→ Defines the blueprint for the pods created by this deployment. -
labels→ Ensures that the created pods match the selector (app: eurekaserver).
Container Specification
spec:
containers:
- name: eurekaserver
image: eazybytes/eurekaserver:s12
ports:
- containerPort: 8070
-
containers→ Defines the containers within the pod. -
name: eurekaserver→ Names the container. -
image: eazybytes/eurekaserver:s12→ Specifies the Docker image for the container. -
ports: containerPort: 8070→ Exposes port 8070 inside the container.
Environment Variables (From ConfigMap)
env:
- name: SPRING_APPLICATION_NAME
valueFrom:
configMapKeyRef:
name: eazybank-configmap
key: EUREKA_APPLICATION_NAME
- name: SPRING_CONFIG_IMPORT
valueFrom:
configMapKeyRef:
name: eazybank-configmap
key: SPRING_CONFIG_IMPORT
-
env→ Defines environment variables for the container. -
valueFrom.configMapKeyRef→ Fetches values from a ConfigMap (eazybank-configmap) instead of hardcoding them. -
SPRING_APPLICATION_NAMEandSPRING_CONFIG_IMPORTare dynamically set using the respective keys from the ConfigMap.
2. Service Configuration
The second part of the YAML file defines a Service that makes the Eureka Server accessible.
apiVersion: v1
kind: Service
metadata:
name: eurekaserver
-
apiVersion: v1→ Indicates that this is a Service resource. -
kind: Service→ Defines this resource as a Service. -
metadata: name: eurekaserver→ Names the service.
Service Selector & Type
spec:
selector:
app: eurekaserver
type: LoadBalancer
-
selector: app: eurekaserver→ Ensures that this service targets pods labeledapp: eurekaserver. -
type: LoadBalancer→ Exposes the service externally with a cloud provider’s load balancer.
Service Port Configuration
ports:
- protocol: TCP
port: 8070
targetPort: 8070
-
protocol: TCP→ Defines TCP as the communication protocol. -
port: 8070→ The port on which the service is exposed. -
targetPort: 8070→ The port inside the pod to which traffic should be directed.
How This Works Together
- Deployment ensures that an instance of the Eureka Server container is running.
- The Service exposes the Eureka Server, allowing other applications to register and communicate with it.
- ConfigMap Integration keeps configurations dynamic, allowing changes without modifying the container image.
Conclusion
This Kubernetes manifest file provides a complete setup for deploying and exposing a Eureka Server. By understanding each section, you can modify and scale this setup for your microservices architecture.
Would you like to see a more advanced version, such as adding Horizontal Pod Autoscaling or Ingress Configuration? Let me know in the comments! 🚀
Top comments (0)