Kubernetes services allow pods to be able to communicate outside Kubernetes cluster. There are three types of services as followed:
ClusterIP is a default internal cluster IP address used when creating a service internal. This cluster IP is only accessible within the cluster and cannot be reached from outside network. When you do
kubectl get services, you will see
CLUSTER-IP in the header and that is the default IP address created for every services. Regardless of what service type it is.
NodePort exposes port on all worker node in Kubernetes cluster. You can define the port manually or let Kubernetes cluster create one for you dynamically. NodePorts are exposed to each worker node and must be unique for each services.
Load balancer is another layer above NodePort. When creating load balancer service, it first creates NodePort and external load balancer virtual IP. Load balancers are specific to cloud providers, and can only be implemented on Azure, GCS, AWS, OpenStack, and OpenSwift.
Managing Kubernetes Services
Below command will list all the services in default namespace.
kubectl get services
[rahil@k8s-master-node ~]$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6h
Below command will list all the services from all namespaces.
kubectl get services --all-namespaces
[rahil@k8s-master-node ~]$ kubectl get services --all-namespaces NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6h kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 6h