Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
The Kubernetes Workshop

You're reading from  The Kubernetes Workshop

Product type Book
Published in Sep 2020
Publisher Packt
ISBN-13 9781838820756
Pages 780 pages
Edition 1st Edition
Languages
Authors (6):
Zachary Arnold Zachary Arnold
Profile icon Zachary Arnold
Sahil Dua Sahil Dua
Profile icon Sahil Dua
Wei Huang Wei Huang
Profile icon Wei Huang
Faisal Masood Faisal Masood
Profile icon Faisal Masood
Mélony Qin Mélony Qin
Profile icon Mélony Qin
Mohammed Abu Taleb Mohammed Abu Taleb
Profile icon Mohammed Abu Taleb
View More author details

Table of Contents (20) Chapters

Preface
1. Introduction to Kubernetes and Containers 2. An Overview of Kubernetes 3. kubectl – Kubernetes Command Center 4. How to Communicate with Kubernetes (API Server) 5. Pods 6. Labels and Annotations 7. Kubernetes Controllers 8. Service Discovery 9. Storing and Reading Data on Disk 10. ConfigMaps and Secrets 11. Build Your Own HA Cluster 12. Your Application and HA 13. Runtime and Network Security in Kubernetes 14. Running Stateful Components in Kubernetes 15. Monitoring and Autoscaling in Kubernetes 16. Kubernetes Admission Controllers 17. Advanced Scheduling in Kubernetes 18. Upgrading Your Cluster without Downtime 19. Custom Resource Definitions in Kubernetes

8. Service Discovery

Overview

In this chapter, we will take a look at how to route traffic between the various kinds of objects that we have created in previous chapters and make them discoverable from both within and outside our cluster. This chapter also introduces the concept of Kubernetes Services and explains how to use them to expose the application deployed using controllers such as Deployments. By the end of this chapter, you will be able to make your application accessible to the external world. You will also know about the different types of Services and be able to use them to make different sets of pods interact with each other.

Introduction

In the past few chapters, we learned about Pods and Deployments, which help us run containerized applications. Now that we are equipped to deploy our applications, in this chapter, we will take a look at some API objects that help us with the networking setup to ensure that our users can reach our application and that the different components of our application, as well as different applications, can work together.

As we have seen in the previous chapters, each Kubernetes Pod gets its IP address. However, setting up networking and connecting everything is not as simple as coding in Pod IP addresses. We can't rely on a single Pod to run our applications reliably. Due to this, we use a Deployment to ensure that, at any given moment, we will have a fixed number of specific kinds of Pods running in the cluster. However, this means that during the runtime of our application, we can tolerate the failure of a certain number of Pods as new pods are automatically created...

Service

A Service defines policies by which a logical set of Pods can be accessed. Kubernetes Services enable communication between various components of our application, as well as between different applications. Services help us connect the application with other applications or users. For example, let's say we have a set of Pods running the frontend of an application, a set of Pods running the backend, and another set of Pods connecting the data source. The frontend is the one that users need to interact with directly. The frontend then needs to connect to the backend, which, in turn, needs to talk to the external data source.

Consider you are making a survey app that also allows users to make visualizations based on their survey results. Using a bit of simplification, we can imagine three Deployments – one that runs the forms' frontend to collect the data, another that validates and stores the data, and a third one that runs the data visualization application...

Ingress

Ingress is an object that defines rules that are used to manage external access to the Services in a Kubernetes cluster. Typically, Ingress acts like a middleman between the internet and the Services running inside a cluster:

Figure 8.17: Ingress

You will learn much more about Ingress and the major motivations for using it in Chapter 12, Your Application and HA. Due to this, we will not cover the implementation of Ingress here.

Now that we have learned about the different types of Services in Kubernetes, we will implement all of them to get an idea of how they would work together in a real-life scenario.

Activity 8.01: Creating a Service to Expose the Application Running on a Pod

Consider a scenario where the product team you're working with has created a survey application that has two independent and decoupled components – a frontend and a backend. The frontend component of the survey application renders the survey forms and needs...

Summary

In this chapter, we covered the different ways in which we can expose our application running on Pods. We have seen how we can use a ClusterIP Service to expose an application inside the cluster. We have also seen how we can use a NodePort Service to expose an application outside the cluster. We have also covered the LoadBalancer and ExternalName Services in brief.

Now that we have created a Deployment and learned how to make it accessible from the external world, in the next chapter, we will focus on storage aspects. There, we will cover reading and storing data on disk, in and across Pods.

lock icon The rest of the chapter is locked
You have been reading a chapter from
The Kubernetes Workshop
Published in: Sep 2020 Publisher: Packt ISBN-13: 9781838820756
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}