1 of 80

Kubernetes

It’s a platform,�not just a deployment tool

2 of 80

3 of 80

Jose Armesto

@fiunchinho�

#bilbostack2019

app.bilbostack.com

  • Schibsted: Developing a Platform as a Service on top of Kubernetes.�
  • CloudBees: Developing features for the Kubernetes-related products.

4 of 80

Agenda

  • How Kubernetes works internally
  • The power of the API
  • Extending Kubernetes functionality
  • Kubernetes as a platform

5 of 80

Agenda

  • How Kubernetes works internally
  • The power of the API
  • Extending Kubernetes functionality
  • Kubernetes as a platform

6 of 80

7 of 80

Let’s program a thermostat

8 of 80

9 of 80

10 of 80

11 of 80

12 of 80

13 of 80

14 of 80

15 of 80

16 of 80

That’s how Kubernetes works

17 of 80

Kubernetes Architecture

Kubernetes is not a monolith. It’s built as a set of processes that are executed inside a cluster of servers.

Some of these processes are called controllers: processes that react to changes in the API.

Psst... Like the thermostat

18 of 80

It’s called Reconciliation Loop

19 of 80

Kubernetes Controllers

Each Kubernetes controller watches the current state of the cluster and compares that to the desired state.

If they don’t match, execute actions to make the current state match the desired state.

20 of 80

21 of 80

22 of 80

What do we mean by state?

  • What applications must be running
  • How traffic must be routed to the applications in the cluster
  • Jobs pending to execute (cronjobs)
  • Much more!

23 of 80

How do we choose the desired state?

24 of 80

Using the API to save the desired state

25 of 80

Agenda

  • How Kubernetes works internally
  • The power of the API
  • Extending Kubernetes functionality
  • Kubernetes as a platform

26 of 80

Kubernetes exposes a model through its API.

This model describes how applications must behave.

Using resources defined in that model we describe the desired state.

We save these resources using the Kubernetes API.

27 of 80

The ReplicaSet object defines how an application is deployed

  • Docker image to use
  • Ports to expose
  • Number of replicas

28 of 80

Save the resource using the API

$ curl -X POST -d @replicaset.json \ "https://k8s_api/apis/apps/v1/namespaces/default/replicasets"

29 of 80

Save the resource using the API

$ curl -X POST -d @replicaset.json \ "https://k8s_api/apis/apps/v1/namespaces/default/replicasets"

30 of 80

Save the resource using the API

$ kubectl create -f "replicaset.json"

31 of 80

The Replication controller is watching

32 of 80

33 of 80

How do we choose the desired state?

34 of 80

How do we choose the desired state?

35 of 80

The Service object defines how an application receives traffic

  • Ports exposed
  • Protocol to use

36 of 80

Save the resource using the API

$ kubectl create -f "service.json"

37 of 80

The Endpoints controller is watching

38 of 80

39 of 80

You can watch resources in the API to react when the desired state and the current state don’t match.

Like the thermostat with temperature

40 of 80

Watching resources using the API

$ curl -X GET \ https://k8s_api/apis/apps/v1/namespaces/ns/replicasets

41 of 80

Watching resources using the API

$ curl -X GET \ https://k8s_api/apis/apps/v1/namespaces/ns/replicasets?watch=true

42 of 80

We will start getting events every time something happens on the watched resources.

When creating a new resource, we get its entire definition.

43 of 80

When the object is modified, we get the new object definition.

44 of 80

We also get an event when a resource is deleted.

45 of 80

Kubernetes controllers

Default controllers watching for changes in specific resources

  • Replication controller
  • Endpoints controller
  • Node controller
  • Service Account controller
  • ...

46 of 80

Kubernetes controllers

But not all the resources are being watched by a controller.

47 of 80

The Ingress object defines how external traffic is mapped to services.

Routing based on the Host header and the path.

48 of 80

Kubernetes controllers

But not all the resources are being watched by a controller.

No one is watching Ingress resources.

Nothing will happen when we save the Ingress object

$ kubectl create -f "ingress.json"

49 of 80

You need to install an Ingress controller

50 of 80

Watches Ingress resources to handle external traffic.

nginx Ingress Controller

51 of 80

Renders the nginx config file whenever a change occurs in Ingress resources.

nginx Ingress Controller

52 of 80

Ingress controllers

  • nginx
  • HAProxy
  • Kong
  • Traefik
  • ...

53 of 80

Agenda

  • How Kubernetes works internally
  • The power of the API
  • Extending Kubernetes functionality
  • Kubernetes as a platform

54 of 80

You can create your own controllers

55 of 80

Controllers can do anything we want

56 of 80

The Ingress object defines how external traffic is mapped to services.

Tries to match the request using the Host header and the path.

57 of 80

Controllers can do anything we want

58 of 80

Creates DNS entries in your cloud DNS service automatically based on your Ingress rules.

External DNS

59 of 80

There are lots of open source controllers

60 of 80

Auto config Prometheus services based on applications running in Kubernetes.

Prometheus discovery

61 of 80

Restart applications when changes are made to ConfigMaps / Secrets.

Reloader

62 of 80

Agenda

  • How Kubernetes works internally
  • The power of the API
  • Extending Kubernetes functionality
  • Kubernetes as a platform

63 of 80

Kubernetes is extensible

The built-in resources exposed by the Kubernetes model may not be enough to describe all the different use cases.

The API lets you make your own resource types called Custom Resources.

You can create a controller that watches your Custom Resources.

64 of 80

This is called the Operator pattern

65 of 80

Retrieve TLS certificates for your applications automatically.

Cert Manager

66 of 80

This Custom Resource describes what TLS certificate we want

  • Which domain
  • From which issuer (Let’s Encrypt, Vault, etc)

67 of 80

Describe what you want, not how you want it

68 of 80

The what is described in the resource

69 of 80

The how is programmed into the Operator

70 of 80

Manage AWS resources directly from Kubernetes.

AWS Service Operator

71 of 80

This Custom Resource describes that we want an S3 Bucket.

72 of 80

Kubernetes as a Platform

Handle all infrastructure problems the same way: no more snowflakes.

Kubernetes primitives and patterns become standard.

Declarative model over imperative model.

73 of 80

More advanced Operators

74 of 80

Provides mechanisms for traffic management like routing, discovery, load balancing, handling failures.

Istio

75 of 80

Build, deploy, and manage modern serverless workloads.

Uses Istio under the hood.

Knative

76 of 80

CI/CD solution for modern cloud applications on Kubernetes.

Uses knative under the hood.

Jenkins X

77 of 80

Kubernetes as a Platform

All of these operators provide a higher level abstraction on top of Kubernetes resources.

Users will use these new layer of resources instead of the built-in Kubernetes resources.

78 of 80

79 of 80

https://codely.tv/pro/bilbostack-19

80 of 80

Jose Armesto

@fiunchinho

#bilbostack2019�

app.bilbostack.com