Description: In this lab, participants will learn how to use services, get to know their different types and learn about debugging
Duration: ±30m
At the end of this lab, each participant will have:*
- Created and edited a Service Object.
- Open https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#creating-a-service and read the example Service specification.
- ✅ Create a Service inside your namespace that will match the following specifications (solution here) :
name: my-app-example-2 selector: label app is my-app-example type: ClusterIP port: 80 targetPort: 80
💡 TIPS: The YAML is used for configuration files : Don't forget that .yaml files indentation is exclusively using spaces and not tabulations.
TYPES | USAGES |
---|---|
ClusterIP | Expose the service on an internal ip (default type) |
NodePort | Expose the service on the IP of each node |
LoadBalancing | The process of efficiently distributing network traffic between multiple services |
-
✅ Deploy this newly created file :
kubectl create -f service-example.yml
-
✅ Let's make sure it was created :
kubectl get services
Congratulations, but it's not over yet. That would have been too simple. It turns out that in a hurry, we made a mistake.
kubectl describe service my-app-example-2
Name: my-app-example-2 Namespace: tatooine Labels: app=my-app-example-2 Annotations: Selector: app=my-app-example Type: ClusterIP IP: 10.244.58.32 Port: http 80/TCP TargetPort: 80/TCP Endpoints: Session Affinity: None Events:
-
✅ Can you spot what's wrong with our service ?
-
✅ Correct the selector and deploy this service :
kubectl create -f service.yaml
-
✅ Or it is also possible to expose your pod in this way :
kubectl expose pod my-app-example-2 --port=80
Now let's test a bit this service and its backend application
-
✅ Deploy a pod within the cluster that will help us to perform some tests
kubectl apply -f debug-pod.yml
-
✅ Enter into an interactive shell of this pod
kubectl exec debug -it /bin/sh
-
✅ Read the documentation on the DNS names for a service: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services
-
✅ From within the debug pod and using curl, find 5 different ways to display the root page of the pod in the backend
🍸 Congratulations, you've been deploying and testing a service 🍸
💡 Tips: Save your file in vim with :
:wq
💡 Tips: To enable line numbers on the vim editor, just enter :
:set nu + enter
💡 Tips: While debugging services, the most common mistake is the selector. Look at the endpoints in the describe service first to see if a backend has been associated.