Kubernetes-Services
An abstract way to expose an application running on a set of Pods as a network service.
With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them
CLUSTER IP
ClusterIP is the default kubernetes service. This service is created inside a cluster and can only be accessed by other pods in that cluster. So basically we use this type of service when we want to expose a service to other pods within the same cluster.
Nodeport:
NodePort opens a specific port on your node/VM and when that port gets traffic, that traffic is forwarded directly to the service.
There are a few limitations and hence its not advised to use NodePort
- only one service per port
- You can only use ports 30000-32767
LoadBalancer:
This is the standard way to expose service to the internet. All the traffic on the port is forwarded to the service. It's designed to assign an external IP to act as a load balancer for the service. There's no filtering, no routing. LoadBalancer uses cloud service
Few limitations with LoadBalancer:
- every service exposed will it's own ip address
- It gets very expensive
Lab for Cluster IP service
1. Create a deployment
2. Access the application which is deployed internally using ClusterIP
Deployment YAML file:
kubectl create -f nginx-deploy.yaml
Kubectl get pods -o wide
Create a ClusterIP service
kubectl create -f nginx-svc-ci.yml
Run below command and You can see the internal-service in the list with a static IP address.
kubectl get svc
To see all the End Points (IP addresses of the Pods which are associated with service)
kubectl describe svc internal-service
Remove one of the pod and monitor the Endpoints
To access the application you need to use the IP address of service with port number.
Delete the CI service
kubectl delete svc internal-service
NodePort Service
Create Node Port service
Create NodePort service
kubectl create -f nginx-svc-np.yml
kubectl get svc
kubectl describe svc external-service
Remove one of the pod and monitor the Endpoints
To access the application you need to use the IP address of service with port number.
You can access the application on browser by providing the IP address of you any node with port number 31869 ...IP:31869
kubectl delete svc external-service
LoadBalancer service
Create LoadBalancer service
kubectl create -f nginx-svc-lb.yml
kubectl get svc
The External IP is to be provided by the load balancer ( more suitable in cloud based environment) if there is not load balancer then the external ip is in the pending state.
kubectl describe svc external-service
Remove one of the pod and monitor the Endpoints
To access the application you need to use the IP address of service with port number.
You can access the application on browser by providing the IP address of you any node with port number 31869 ...IP:31869
kubectl delete svc external-service
Delete the Deploy
kubectl delete deploy nginx-deployment
Ingress
Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.
internet
|
[ Ingress ]
--|-----|--
[ Services ]
An Ingress may be configured to give Services externally-reachable URLs, load balance traffic, terminate SSL / TLS, and offer name-based virtual hosting. An Ingress controller is responsible for fulfilling the Ingress, usually with a load balancer, though it may also configure your edge router or additional frontends to help handle the traffic.
Comments
Post a Comment