From b2112c0f93c72b1d670217eeee0a6fe9d1c40517 Mon Sep 17 00:00:00 2001 From: Murad Korejo Date: Mon, 10 Apr 2017 18:40:52 -0500 Subject: [PATCH] Improvements to kubernetes-basics/expose-intro.html (#3103) * Massive updates to expose-intro.html Updates to the non-interactive tutorial on exposing apps via services * more updates to expose-intro * fixed broken link * fixed some wording * removed extra space * sub backticks for code and newline * added small legend to fist svg * fixed svg scaling * removed extra div --- .../kubernetes-basics/expose-intro.html | 213 +++--- .../public/images/module_04_services.svg | 643 +++++++----------- 2 files changed, 335 insertions(+), 521 deletions(-) diff --git a/docs/tutorials/kubernetes-basics/expose-intro.html b/docs/tutorials/kubernetes-basics/expose-intro.html index 0750836cd43b8..12170e56e7a46 100644 --- a/docs/tutorials/kubernetes-basics/expose-intro.html +++ b/docs/tutorials/kubernetes-basics/expose-intro.html @@ -12,126 +12,99 @@
-
- -
- -
-

Objectives

-
    -
  • Learn about Kubernetes Services.
  • -
  • Learn about Kubernetes Labels.
  • -
  • Expose an application outside Kubernetes.
  • -
-
- -
-

Kubernetes Services

- -

While Pods do have their own unique IP across the cluster, those IPs are not exposed outside Kubernetes. Taking into account that over time Pods may be terminated, deleted or replaced by other Pods, we need a way to let other Pods and applications automatically discover each other. Kubernetes addresses this by grouping Pods in Services. A Kubernetes Service is an abstraction layer which defines a logical set of Pods and enables external traffic exposure, load balancing and service discovery for those Pods.

- -

This abstraction will allow us to expose Pods to traffic originating from outside the cluster. Services have their own unique cluster-private IP address and expose a port to receive traffic. If you choose to expose the service outside the cluster, the options are:

-
    -
  • LoadBalancer - provides a public IP address (what you would typically use when you run Kubernetes on GCP or AWS)
  • -
  • NodePort - exposes the Service on the same port on each Node of the cluster using NAT (available on all Kubernetes clusters, and in Minikube)
  • -
-
-
-
-

Summary:

-
    -
  • Exposing Pods to external traffic
  • -
  • Load balancing traffic across multiple Pods
  • -
  • Using labels
  • -
-
-
-

- A Kubernetes Service is an abstraction layer which defines a logical set of Pods and enables external traffic exposure, load balancing and service discovery for those Pods. -

-
-
-
-
- -
-
-

Services overview

-
-
- -
-
-

-
-
-
- -
-
- -

A Service provides load balancing of traffic across the contained set of Pods. This is useful when a service is created to group all Pods from a specific Deployment (our application will make use of this in the next module, when we'll have multiple instances running).

- -

Services are also responsible for service-discovery within the cluster (covered in Accessing the Service). This will for example allow a frontend service (like a web server) to send traffic to a backend service (like a database) without worrying about Pods.

- -

Services match a set of Pods using Label Selectors, a grouping primitive that allows logical operation on Labels.

- -
-
-
-

You can create a Service when you start a Deployment by adding --expose as a parameter for the kubectl run command

-
-
-
- -
- -
-
-

Labels are key/value pairs that are attached to objects, such as Pods and you can think of them as hashtags from social media. They are used to organize related objects in a way meaningful to the users like:

-
    -
  • Production environment (production, test, dev)
  • -
  • Application version (beta, v1.3)
  • -
  • Type of service/server (frontend, backend, database)
  • -
-
-
-
-

Labels are key/value pairs that are attached to objects

-
-
-
-
-
-
-

Labels

-
-
- -
-
-

-
-
-
-
-
- -

Labels can be attached to objects at the creation time or later and can be modified at any time. - The kubectl run command sets some default Labels/Label Selectors on the new Pods/ Deployment. The link between Labels and Label Selectors defines the relationship between the Deployment and the Pods it creates.

- -

Now let's expose our application with the help of a Service, and apply some new Labels.

-
-
-
- - -
- +
+ +
+
+

Objectives

+
    +
  • Learn about a Service in Kubernetes
  • +
  • Understand how labels and LabelSelector objects relate to a Service
  • +
  • Expose an application outside a Kubernetes cluster using a Service
  • +
+
+ +
+

Overview of Kubernetes Services

+ +

Kubernetes Pods are mortal. Pods in fact have a lifecycle. When a worker node dies, the Pods running on the Node are also lost. A ReplicationController might then dynamically drive the cluster back to desired state via creation of new Pods to keep your application running. As another example, consider an image-processing backend with 3 replicas. Those replicas are fungible; the front-end system should not care about backend replicas or even if a Pod is lost and recreated. That said, each Pod in a Kubernetes cluster has a unique IP address, even Pods on the same Node, so there needs to be a way of automatically reconciling changes among Pods so that your applications continue to function. Enter Services. A Service in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them. Services enable a loose coupling between dependent Pods. A Service is defined using YAML (preferred) or JSON, like all Kubernetes objects. The set of Pods targeted by a Service is usually determined by a LabelSelector (see below for why you might want a Service without including selector in the spec).

+ +

Although Pods each have a unique IP address, those IPs are not exposed outside the cluster without a Service. Services allow your applications to receive traffic. Services can be exposed in different ways by specifying a type in the ServiceSpec:

+
    +
  • ClusterIP (default) - Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster.
  • +
  • NodePort - Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service accessible from outside the cluster using :. Superset of ClusterIP.
  • +
  • LoadBalancer - Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Service. Superset of NodePort.
  • +
  • ExternalName - Exposes the Service using an arbitrary name (specified by externalName in the spec) by returning a CNAME record with the name. No proxy is used. This type requires v1.7 or higher of kube-dns.
  • +
+

More information about the different types of Services can be found in the Using Source IP tutorial. Also see Connecting Applications with Services.

+

Additionally, note that there are some use cases with Services that involve not defining selector in the spec. A Service created without selector will also not create the corresponding Endpoints object. This allows users to manually map a Service to specific endpoints. Another possibility why there may be no selector is you are strictly using type: ExternalName.

+
+
+
+

Summary

+
    +
  • Exposing Pods to external traffic
  • +
  • Load balancing traffic across multiple Pods
  • +
  • Using labels
  • +
+
+
+

A Kubernetes Service is an abstraction layer which defines a logical set of Pods and enables external traffic exposure, load balancing and service discovery for those Pods.

+
+
+
+
+ +
+
+

Services and Labels

+
+
+ +
+
+

+
+
+ +
+
+

A Service routes traffic across a set of Pods. Services are the abstraction that allow pods to die and replicate in Kubernetes without impacting your application. Discovery and routing among dependent Pods (such as the frontend and backend components in an application) is handled by Kubernetes Services.

+

Services match a set of Pods using labels and selectors, a grouping primitive that allows logical operation on objects in Kubernetes. Labels are key/value pairs attached to objects and can be used in any number of ways:

+
    +
  • Designate objects for development, test, and production
  • +
  • Embed version tags
  • +
  • Classify an object using tags
  • +
+ +
+
+
+

You can create a Service at the same time you create a Deployment by using
--expose in kubectl.

+
+
+
+ +
+ +
+
+

+
+
+
+
+
+

Labels can be attached to objects at creation time or later on. They can be modified at any time. Let's expose our application now using a Service and apply some labels.

+
+
+
+ +
diff --git a/docs/tutorials/kubernetes-basics/public/images/module_04_services.svg b/docs/tutorials/kubernetes-basics/public/images/module_04_services.svg index a971ad95ddc8c..a12c097bcc5ce 100644 --- a/docs/tutorials/kubernetes-basics/public/images/module_04_services.svg +++ b/docs/tutorials/kubernetes-basics/public/images/module_04_services.svg @@ -1,9 +1,6 @@ - - - - + + + + + + + + + + + + + + + + Docker + Kubelt + + + Layer 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pod + + + Node + + + + + \ No newline at end of file