Kubernetes Introduction WOJCIECH BARCZYSKI (hiring) Senior - - PowerPoint PPT Presentation

kubernetes
SMART_READER_LITE
LIVE PREVIEW

Kubernetes Introduction WOJCIECH BARCZYSKI (hiring) Senior - - PowerPoint PPT Presentation

Kubernetes Introduction WOJCIECH BARCZYSKI (hiring) Senior Software Engineer Lead of Warsaw Team - SMACC System Engineer background Interests: working software Hobby: teaching software engineering BACKGROUND A top AI FinTech


slide-1
SLIDE 1

Kubernetes

Introduction

slide-2
SLIDE 2

WOJCIECH BARCZYŃSKI

(hiring) Senior Software Engineer Lead of Warsaw Team - SMACC System Engineer background Interests: working software Hobby: teaching software engineering

slide-3
SLIDE 3

BACKGROUND

A top AI FinTech ➡ microservices and k8s Before renew tech stack of a top Indonesian mobile ecommerce 3.5y with Openstack, 1000+ nodes, 21 data centers I do not like INFRA :D

slide-4
SLIDE 4

KUBERNETES Kubernetes - greek for helmsman Run and Manages containers Inspired by Google's Borg Integrated with AWS, GCP, Azure Becoming an integration platform for large ecosystem Manages Applications not Machines!

slide-5
SLIDE 5

GOALS Utilized resources nearly 100% Get to applications/services mindset Enforce loosely couple software - 12factor apps, Amazon-API approach Best practises included, e.g., name service, metadata discovery, ...

slide-6
SLIDE 6

CURRENT WINNER « Amazon joined Kubernetes

  • n 10.08.2017 »
slide-7
SLIDE 7

WHY KUBERNETES?

Data Center as a Black Box Batteries for your (12factor) apps

slide-8
SLIDE 8

WHY KUBERNETES?

Give you complete control over your application with simple yaml config files Use labels to auto-wire your app to monitoring, logging, and alarming Let you to, almost forget, about the infrastructure

slide-9
SLIDE 9

Batteries

Load Balancing Name Service Discovery Metadata and Annotation support Decoupled interface and implementation Labeled based matching

slide-10
SLIDE 10

DATA CENTER AS A BLACK BOX

slide-11
SLIDE 11

KUBERNETES

Kubernetes Ingress Controller Node Node Node Node App Docker Image Service Deployment k8s config:

make docker_push; kubectl create -f app-srv-dpl.yaml

slide-12
SLIDE 12

SCALE UP! SCALE DOWN!

Kubernetes Ingress Controller Node Node Node Node App App App scale 3x

kubectl --replicas=3 -f app-srv-dpl.yaml

slide-13
SLIDE 13

INGRESS CONTROLLER

api.smacc.io/v1/users ➡ service: users-v1 api.smacc.io/v2/users ➡ service: users-v2 api.smacc.io/accounts ➡ service: accounts smacc.io ➡ service: website

slide-14
SLIDE 14

INGRESS CONTROLLER

API BACKOFFICE 1 DATA WEB ADMIN BACKOFFICE 2 BACKOFFICE 3 A P I . D O M A I N . C O M D O M A I N . C O M / W E B B A C K O F F I C E . D O M A I N . C O M ORCHESTRATOR PRIVATE NETWORK INTERNET API LISTEN (DOCKER, SWARM, MESOS...)

slide-15
SLIDE 15

ROLLING UPDATES!

Kubernetes Ingress Controller Node Node Node Node App App App Docker Image v2

kubectl set image deployment/app app=app:v2.0.0

slide-16
SLIDE 16

ROLLING UPDATES!

Kubernetes Ingress Controller Node Node Node Node App App Docker Image v2

slide-17
SLIDE 17

ROLLING UPDATES!

Kubernetes Ingress Controller Node Node Node Node App App Docker Image v2 App

slide-18
SLIDE 18

ROLLING UPDATES!

Kubernetes Ingress Controller Node Node Node Node App App App Docker Image v2

slide-19
SLIDE 19

LOAD BALANCING

Kubernetes Worker Kubernetes Worker Kubernetes Worker Node Port 30000 Node Node App App Kubernetes Worker Node App

<<Requests>>

B Service Port 30000 Port 30000 Port 30000

Load Balancer

slide-20
SLIDE 20

RESISTANCE!

Kubernetes Ingress Controller Node Node Node Node App App App

slide-21
SLIDE 21

RESISTANCE!

Kubernetes Ingress Controller Node Node Node App App App

slide-22
SLIDE 22

RESISTANCE!

When the node dies in flames When other apps (with higher guaranteed quotas) eats all memory When you need to drain nodes before upgrade You can easily scale up, create machine and join it to cluster (easier with kops or on GCE)

slide-23
SLIDE 23

FEDERATION

Global LoadBalancer

App App App

On-premise Poland Amazon eu-west-1 Google asia-southeast1

slide-24
SLIDE 24

MUCH MORE

Plug-and-play integrations: integration with AWS, Google Cloud Platform, and Azure multiple drivers for network, storage,... you can run on minikube

slide-25
SLIDE 25

MUCH MORE

Kubernetes administrated with kubernetes: everything run in pods e.g., you deploy your log collectors for k8s as pods:

http://wbarczynski.pl/centralized-logging-for-kubernetes-with-fluentd-and- elasticsearch/

slide-26
SLIDE 26

BASIC CONCEPTS Name Purpose Service Interface Service Name, port, labels, annotations Deployment Factory How many pods with which docker images, labels Pod Implementation 1+ docker images running in 1 pod

slide-27
SLIDE 27

BASIC CONCEPTS

config / secret ➡ config and files ingress-controller ➡ url pattern ➡ service

slide-28
SLIDE 28

SERVICE

service.yaml:

apiVersion: v1 kind: Service metadata: name: api-status spec: ports:

  • port: 80

protocol: TCP selector: app: api-status

slide-29
SLIDE 29

SERVICE

# create the service and deployment kubectl create -f api-status-srv.yaml kubectl create -f api-status-dpl.yaml # get to a running docker (in a pod) kubectl -it exec app-999-8zh1p /bin/bash # check whether name service works curl http://api-status/health OK

slide-30
SLIDE 30

BASIC CONCEPTS

Service Pods Labels Deployment Deployment << Creates >> << Creates >> Service Name Service Port

slide-31
SLIDE 31

deployment.yaml

apiVersion: apps/v1beta1 kind: Deployment metadata: name: api-status-nginx app: api-status spec: replicas: 1 template: metadata: labels: name: api-status-nginx app: api-status spec: containers:

  • name: nginx

image: nginx

slide-32
SLIDE 32

CONFIG

env variables in deployment:

env:

  • name: SEARCH_ENGINE_USER

value: mighty_mouse

slide-33
SLIDE 33

CONFIG

feed envs from configmaps:

env:

  • name: SEARCH_ENGINE_USER

valueFrom: configMapKeyRef: name: my-config key: search.user

slide-34
SLIDE 34

CONFIG

you can ship files using configmaps/secrets

kubectl create configmap my-config-file

  • -from-file=config.json
slide-35
SLIDE 35

CONFIG

You can also run your own: HashiCorp Consul or etcd HashiCorp Vault

slide-36
SLIDE 36

METADATA AND ANNOTATIONS

Auto-wiring Precise discovery Reporting Labeling targets for security scans Labeling critical services for oncall (see alertmanager)

slide-37
SLIDE 37

MONITORING WITH KUBERNETES

You deploy a memcached Exposed its prometheus metrics on metrics/ How to ship metrics?

slide-38
SLIDE 38

ANNOTATIONS!

memcached-0-deployment.yaml

https://github.com/skarab7/kubernetes-memcached

  • apiVersion: v1

kind: Service metadata: name: memcached-0 labels: app: memcached kubernetes.io/name: "memcached" role: shard-0 tier: backend annotations: prometheus.io/scrape: "true" prometheus.io/scheme: "http" prometheus.io/path: "metrics" prometheus.io/port: "9150"

slide-39
SLIDE 39

INGRESS CONTROLLER WITH TRAEFIK?

slide-40
SLIDE 40

ANNOTATIONS!

Use traefik instead of built-in reverse proxy

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: api-status namespace: production annotations: kubernetes.io/ingress.class: traefik spec: rules:

  • host: api.example.com

http: paths:

  • path: /status

backend: serviceName: api-status

slide-41
SLIDE 41

LABELS!

Monitoring rule that uses labels: AlertManager

ALERT ProductionAppServiceInstanceDown IF up { environment = "production", app =~ ".+"} == 0 FOR 4m ANNOTATIONS { summary = "Instance of {{$labels.app}} is down", description = " Instance {{$labels.instance}} of app {{$labels.app}} has been down for more than 4 minutes" }

slide-42
SLIDE 42

LABELS!

Call sb if the label is severity=page: AlertManager

group_by: [cluster] # If an alert isn't caught by a route, send it to the pager. receiver: team-pager routes:

  • match:

severity: page receiver: team-pager receivers:

  • name: team-pager
  • psgenie_configs:
  • api_key: $API_KEY

teams: example_team

slide-43
SLIDE 43

THERE IS SO MUCH MORE

resource quotas events in Kubernetes readiness probes liveness probes volumes stateful namespaces ...

slide-44
SLIDE 44

KUBERENTES

Awesome command-line Resilient platform simple YAML files to setup your service, service discovery included annotations and metadata discovery included

slide-45
SLIDE 45

0.1 ➡ 1.0

Your component needs to get much more smarter.

slide-46
SLIDE 46

SERVICE SELF-CONSCIOUSNESS

Your endpoint: metrics/ alertrules/- [WIP] health/ or healthz/ info/

slide-47
SLIDE 47

DEEP LOOK INSIDE

when I am ready to serve requests when I need to restart myself what to do when dependent services are down ...

slide-48
SLIDE 48

DEEP LOOK INSIDE

Am I really stateless? Caching? fail-fast, start fast

slide-49
SLIDE 49

RELATIONS WITH OTHERS

master-worker relationships waiting for other resources / services

slide-50
SLIDE 50

12FACTOR APPS

find services by name or URI move the important config to environment variables

slide-51
SLIDE 51

LOGGING

logstash json format make configurable with ENV variable

EFK or ELK

slide-52
SLIDE 52

WHAT WITH YOUR DATABASES

Keep it in a separated (k8s) cluster The best, go with DaaS With Stateful, you can run your db in k8s

Long discussion...

slide-53
SLIDE 53

MIGRATION OF ENV

Staging, production, canary, green/blue ...: If you have $$$, have a separated k8s cluster If not, use Namespaces

slide-54
SLIDE 54

APPS IN NEW WORLD

12 factor apps (Heroku, 2012) much much smarter much faster much more predictable much harder to develop :D Forging experience into code [WIP]: https://github.com/microdevs

slide-55
SLIDE 55

THANK YOU

slide-56
SLIDE 56

(hiring) Wojciech Barczyński (wojciech.barczynski@smacc.io)

slide-57
SLIDE 57

Backup slides

slide-58
SLIDE 58

6 + 1 STEPS

The big 1 - making your app smarter

slide-59
SLIDE 59
  • 1. CLEAN UP

Single script for repo - Makefile [1] Resurrect the README

[1] With zsh or bash auto-completion plugin in your terminal.

slide-60
SLIDE 60
  • 2. GET BACK ALL THE KNOWLEDGE

Puppet, Chef, ... ➡ Dockerfile Check the instances ➡ Dockerfile, README.rst Nagios, ... ➡ README.rst, checks/

slide-61
SLIDE 61
  • 3. INTRODUCE RUN_LOCAL

make run_local A nice section on how to run in README.rst Use: docker-compose The most crucial point.

slide-62
SLIDE 62
  • 4. GET TO KUBERNETES

make kube_create_config make kube_apply Generate the yaml files if your envs differ

slide-63
SLIDE 63
  • 5. CONTINUOUS DEPLOYMENT

Simple components: test code, build docker, push to docker repo run the rolling update: kubectl set image deployment/api-status nginx=nginx:1.9.1 I use TravisCI

slide-64
SLIDE 64
  • 5. CONTINUOUS DEPLOYMENT

Complex components: with label-based matching, the sky is the limit

slide-65
SLIDE 65
  • 6. KEEP IT RUNNING

Brigde the new with old: You can add your external servies to the k8s Name Service You can bridge Kubernetes services to your Service Discovery [1]

[1] You can subscribe to K8S events to keep, e.g., your consul in sync