Day 5: Kubernetes Services – Connecting Your Applications
Welcome to Day 5 of the Zero to Platform Engineer in 30 Days challenge! Yesterday, we explored Deployments and Scaling in Kubernetes, learning how to manage application lifecycles and scale them effectively. Today, we’ll dive into Kubernetes Services, which are essential for enabling communication between your applications and making them accessible to users.
What Are Kubernetes Services?
In Kubernetes, a Service is an abstraction that defines a logical set of Pods and a policy for accessing them. Services allow applications to:
Without Services, Pods would be difficult to communicate with because their IP addresses change frequently as they are created or destroyed.
Types of Kubernetes Services
There are four main types of Services, each with a specific purpose:
How Services Fit Into Platform Engineering
As a Platform Engineer, Kubernetes Services are critical for:
Hands-On: Creating Kubernetes Services
Step 1: Deploy a Simple Application
Let’s deploy an example application to work with.
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
image: nginx
ports:
- containerPort: 80
kubectl apply -f nginx-deployment.yaml
kubectl get pods
Step 2: Create a ClusterIP Service
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
kubectl apply -f nginx-service.yaml
kubectl get services
kubectl exec -it nginx-deployment -- curl http://nginx-service
🎯 What’s happening? The Service provides a stable IP and DNS name (nginx-service) that can be used to communicate with the Pods.
Step 3: Create a NodePort Service
type: NodePort
kubectl apply -f nginx-service.yaml
kubectl get services
curl http://<node-ip>:<node-port>
🎯 Pro tip: Use minikube service nginx-service if you’re running Minikube.
Step 4: Expose the Service with a LoadBalancer (Optional)
If you’re using a cloud provider, you can change the type to LoadBalancer:
type: LoadBalancer
kubectl apply -f nginx-service.yaml
kubectl get services
Activity for Today
What’s Next?
With Services, you now know how to connect your applications and expose them to users. Tomorrow, we’ll explore ConfigMaps and Secrets, which help manage configuration and sensitive data in Kubernetes.
👉 Check it out here: Zero to Platform Engineer Repository
Feel free to clone the repo, experiment with the code, and even contribute if you’d like! 🚀
Follow the Series!
🎉 Don’t miss a single step in your journey to becoming a Platform Engineer! 🎉
This post is just the beginning. Here’s what we’ve covered so far and what’s coming up next:
AWS certified professional
6moThis is very helpful to refresh the knowledge for those who already familiar with kubernetes Alex Parra