#KubernetesSummarySeries - Module 6 [k8s Services]
Kubernetes Services
Service is a kubernetes object which provides a stable and reliable networking for pods.
??It's not a good idea to directly connect to a pod. Why ?(Below is the answer)
When a pod fails , it gets replaced by new ones with a new IP. Scaling up/down ,Rolling updates also replaces the pods where the IP addresses are changed. All in all this creates a massive IP churn.
Every service gets its own stable IP address , DNS name and port.
When using a service object , the pods can easily scale in/out , fails , rollout/rollback without impacting the client.
Service observes the changes and update its list of healthy pods but it never changes the IP,DNS and port. It does this through a combination of label selection and a construct called an Endpoints object.
Services are loosely coupled with pods via labels and selectors. For a service to send traffic to a pod,the pod needs every label the service is selecting on.
Types of services
Kubernetes supports several types of services :
?? ClusterIP - Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default that is used if you don't explicitly specify a type for a Service. You can expose the Service to the public internet using an Ingress or a Gateway.
?? NodePort - Exposes the Service on each Node's IP at a static port (the NodePort). To make the node port available, Kubernetes sets up a cluster IP address, the same as if you had requested a Service of type: ClusterIP.
?? LoadBalancer - Exposes the Service externally using an external load balancer. Kubernetes does not directly offer a load balancing component; you must provide one, or you can integrate your Kubernetes cluster with a cloud provider.
?? ExternalName - Maps the Service to the contents of the externalName field. The mapping configures your cluster's DNS server to return a CNAME record with that external hostname value. No proxying of any kind is set up.
领英推荐
Service Creation
A service can be created in two ways -
?? Imperative way - Kubectl command can be used to deploy a deployment and create a service.
kubectl apply -f <deploy yaml>
kubectl expose deployment <service-name> --type=<service-type>
kubectl describe svc <service-name>
?? Declarative way - Using manifest with v1 core API group.
Endpoints / Endpoint Slices
Every Time a service is created , Kubernetes automatically creates an associated Endpoints object. It is used to store a dynamic list of healthy pods matching the service label selector.
kubectl get endpointslices
kubectl describe endpointslices <endpointslice-name>
Service Discovery
Service discovery is implemented by kubernetes in a couple of ways -
?? DNS
?? Environment Variables
?? Stay Tuned for More !
I will be sharing more insights in the upcoming articles of our #KubernetesSummarySeries. Make sure you follow ??Gaurav Sharma to stay updated and not miss out on the next chapters of this series !
#Kubernetes #CloudNative #DevOps #Microservices #Containerization #Automation #Scalability #Innovation #TechTrends #SoftwareDevelopment
Helping Online Marketplaces and Agencies Scale Rapidly & Increase Efficiency through software integrations and automations
2 个月kubernetes is like the swiss army knife for cloud! what’s piquing your interest here?