Working With Kubernetes Services

Working with kubernetes services.

Kubernetes services allow pods to be able to communicate outside Kubernetes cluster. There are three types of services as follows:

ClusterIP
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 service. Regardless of what service type it is.

NodePort
NodePort exposes port on all worker nodes 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 service.

Load balancer
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

List Services

The below command will list all the services in default namespace.

kubectl get services

Output:

[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

The below command will list all the services from all namespaces.

kubectl get services --all-namespaces

Output:

[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

Leave a Comment

Scroll to Top