Difficulty: Beginner
Estimated Time: 30 minutes

Distributing applications across a cluster can significantly complicate the way you design, run, and monitor an application. Kubernetes is an operating system that reduces the complexity of distributed computing. Service discovery is important because it allows you to find and access services that are distributed across a cluster. The Kubernetes Service resource is central to service discovery and makes it easier to connect applications across your cluster, compared to imperative application networking. With the Service resource, you can declare a policy and approach to access a set of Pods. Once you understand how Services can be declared and controlled, it should then be easier for you to design solutions orchestrated across a cluster.

The Service resource can be defined with these four types:

  • ClusterIP
  • NodePort
  • LoadBalancer
  • ExternalName

This scenario covers the first three types, which solve your service discovery needs. The ExternalName type and other features like headless services are covered in the another scenario, Kubernetes Networking: External Services.

In the following steps you will learn:

  • How to expose an application with a service using just labels
  • How to expose an application using ClusterIP, NodePort, and LoadBalancer
  • How to set port, targetPorts, and nodePort settings
  • How kube-proxy and a DNS process are key control plane components for service discovery

Of Kubernetes Service you underestimate the power. See, continue to try and you will. Herh herh herh. -- Yoda speak

Discovering services through simple labels provided from environment settings makes calling other services easily from your application. When you decide on a Kubernetes cluster to use, one of the first things you should investigate is what service flavor provides the DNS resolutions.

This lesson does not cover more complex topics such as meshing, ingressing, egressing nor security protections. But, with these fundamentals, you can now expand into those topics.

Here are some additional Katacoda courses:

Lessons Learned

With these steps you have learned:

  • ✔ How to expose an application with a Service using just labels
  • ✔ How to expose an application using ClusterIP, NodePort, and LoadBalancer
  • ✔ How to set port, targetPorts, and nodePort settings
  • ✔ How kube-proxy and a DNS process are key control plane components for service discovery

References

  • Kubernetes Fundamentals: Experience First Cluster
  • Kubernetes Fundamentals: Scaling and Updating an Application
  • Kubernetes Fundamentals: Deploy and Run a Multicontainer Application

For a deeper understanding of these topics and more join
Jonathan Johnson
at various conferences, symposiums, workshops, and meetups.

Software Architectures ★ Speaker ★ Workshop Hosting ★ Kubernetes & Java Specialist

Kubernetes Networking: Service Discovery

Step 1 of 8

Your Kubernetes Cluster

For this scenario, Katacoda has just started a fresh Kubernetes cluster for you. Verify it's ready for your use:

kubectl version --short && \ kubectl get componentstatus && \ kubectl get nodes && \ kubectl cluster-info

The Helm package manager used for installing applications on Kubernetes is also available:

helm version --short

Kubernetes Dashboard

You can administer your cluster with the kubectl CLI tool or use the visual Kubernetes Dashboard. Use this script to access the protected Dashboard:

token.sh