Table of contents
- Congratulations ๐ on your learning on Deployments in K8s on Day 33
- What are Services in K8s
- Task-1:
- Task-2:
- Create a ClusterIP Service for accessing the todo-app from within the cluster
- Create a ClusterIP Service definition for your todo-app Deployment in a YAML file.
- Apply the ClusterIP Service definition to your K8s (minikube) cluster using the kubectl apply -f cluster-ip-service.yml -n <namespace-name> command.
- Verify that the ClusterIP Service is working by accessing the todo-app from another Pod in the cluster in your Namespace.
- Task-3:
- Create a LoadBalancer Service for accessing the todo-app from outside the cluster
- Create a LoadBalancer Service definition for your todo-app Deployment in a YAML file.
- Apply the LoadBalancer Service definition to your K8s (minikube) cluster using the kubectl apply -f load-balancer-service.yml -n <namespace-name> command.
- Verify that the LoadBalancer Service is working by accessing the todo-app from outside the cluster in your Namespace.
Congratulations ๐ on your learning on Deployments in K8s on Day 33
What are Services in K8s
- In Kubernetes, Services are objects that provide stable network identities to Pods and abstract away the details of Pod IP addresses. Services allow Pods to receive traffic from other Pods, Services, and external clients.
Task-1:
Create a Service for your todo-app Deployment from Day-32
Create a Service definition for your todo-app Deployment in a YAML file.
Apply the Service definition to your K8s (minikube) cluster using the
kubectl apply -f service.yml -n <namespace-name>
command.Verify that the Service is working by accessing the todo-app using the Service's IP and Port in your Namespace.
- Create a
Service.yaml
file for yourdjango-todo-app
Deployment from Day 32
apiVersion: v1
kind: Service
metadata:
name: todo-service
namespace: django-app
spec:
type: NodePort
selector:
app: todo-app
ports:
# By default and for convenience, the `targetPort` is set to the same value as the `port` field.
- port: 80
targetPort: 8000
# Optional field
# By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
nodePort: 30007
- Apply the updated deployment using the command
kubectl apply -f service.yaml -n <namespace>
- To get services , we use
kubectl get svc -n <namespace>
and for wide overview we can usekubectl get svc -o wide -n <namespace>
- After that use this command
minikube ssh
curl -L http://<cluster-IP>
Task-2:
Create a ClusterIP Service for accessing the todo-app from within the cluster
Create a ClusterIP Service definition for your todo-app Deployment in a YAML file.
Apply the ClusterIP Service definition to your K8s (minikube) cluster using the
kubectl apply -f cluster-ip-service.yml -n <namespace-name>
command.Verify that the ClusterIP Service is working by accessing the todo-app from another Pod in the cluster in your Namespace.
- Create a YAML file called
cluster-ip-service.yml
with the following contents:
apiVersion: v1
kind: Service
metadata:
name: todo-app-cluster-ip-service
namespace: django-app
spec:
type: ClusterIP
selector:
app: todo-app
ports:
- port: 80
targetPort: 8000
- Apply the ClusterIP Service definition to your Kubernetes cluster using the following command:
kubectl apply -f cluster-ip-service.yml -n django-app
- Verify that the ClusterIP Service is working by accessing the todo-app from another Pod in the cluster in your Namespace. You can find the ClusterIP Service's IP by running the following command
kubectl get svc -n <namespace> && kubectl get svc -o wide -n <namespace>
- After that use this command
minikube ssh
curl -L http://<cluster-IP>
Task-3:
Create a LoadBalancer Service for accessing the todo-app from outside the cluster
Create a LoadBalancer Service definition for your todo-app Deployment in a YAML file.
Apply the LoadBalancer Service definition to your K8s (minikube) cluster using the
kubectl apply -f load-balancer-service.yml -n <namespace-name>
command.Verify that the LoadBalancer Service is working by accessing the todo-app from outside the cluster in your Namespace.
- Create a YAML file called
load-balancer-service.yml
with the following contents:
apiVersion: v1
kind: Service
metadata:
name: todo-app-load-balancer-service
namespace: django-app
spec:
type: LoadBalancer
selector:
app: todo-app
ports:
- port: 80
targetPort: 8000
- Apply the LoadBalancer Service definition to your Kubernetes cluster using the following command:
kubectl apply -f load-balancer-service.yml -n django-app
- Verify that the LoadBalancer Service is working by accessing the todo-app from outside the cluster in your Namespace. You can find the LoadBalancer Service's IP by running the following command:
kubectl get svc -n <namespace> && kubectl get svc -o wide -n <namespace>
- After that use this command
minikube ssh
curl -L http://<clister-IP>
- Your day 34 successfully completed ๐ฅ๐ฅ๐ฅ
Happy Learning
Thanks For Reading! :)
sriparthu ๐ฅ
ย