introduction to kubernetes - bolbeck.com

35
Introduction to Kubernetes Juan Peredo https://www.linkedin.com/in/juanperedotech

Upload: others

Post on 25-Apr-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Kubernetes - bolbeck.com

Introduction to KubernetesJuan Peredo

https://www.linkedin.com/in/juanperedotech

Page 2: Introduction to Kubernetes - bolbeck.com

A couple walks into a bar...

Page 3: Introduction to Kubernetes - bolbeck.com

The food ordering process

Page 4: Introduction to Kubernetes - bolbeck.com

Kubernetes

Page 5: Introduction to Kubernetes - bolbeck.com

Images and containers

• Images package apps and all their dependencies

• Images can be shared using container registries like Docker Hub

• Containers are ephemeral image instances

• Kubernetes manages container lifecycle automatically

Page 6: Introduction to Kubernetes - bolbeck.com

Moving to Kubernetes

• Pods: Smallest deployment unit

• Replicaset: Controls number of pod instances

• Deployment: Where all the magic happens

Page 7: Introduction to Kubernetes - bolbeck.com

Adding dessert

Satellite resources helpful when running an app:

• Services: Port definition

• ConfigMaps: App Configuration

• Secrets: Sensitive data (64bit encoded)

• And many more ...

All resources defined using YAML manifests

Page 8: Introduction to Kubernetes - bolbeck.com

Getting started

Page 9: Introduction to Kubernetes - bolbeck.com

Basic anatomy of a YAML manifest

apiVersion: v1kind: [Service|Pod|Deployment|etc...]metadata: annotations: foo: bar labels: app: mylabel name: myname[spec|data]:

Page 10: Introduction to Kubernetes - bolbeck.com

Our first command

Page 11: Introduction to Kubernetes - bolbeck.com

apiVersion: v1kind: Podmetadata: creationTimestamp: null labels: run: mariadb name: mariadbspec: containers: - image: mariadb name: mariadb ports: - containerPort: 3306 ...

Page 12: Introduction to Kubernetes - bolbeck.com

Our second command

Page 13: Introduction to Kubernetes - bolbeck.com

apiVersion: apps/v1kind: Deploymentmetadata: labels: app: mariadb name: mariadbspec: replicas: 1 selector: matchLabels: app: mariadb template: metadata: labels: app: mariadb spec: containers: - image: mariadb name: mariadb ports: - containerPort: 3306 ...

Page 14: Introduction to Kubernetes - bolbeck.com

Demo time

• Goals

• Take an application all the way to deployment in K8s

• Everything as code

• Repo:

• https://bitbucket.org/Bolbeck/cwit_2020

Page 15: Introduction to Kubernetes - bolbeck.com

Demo roadmap

Page 16: Introduction to Kubernetes - bolbeck.com

Our application

Page 17: Introduction to Kubernetes - bolbeck.com

Running our app

• Build custom Node app image with Docker

• Run with Docker-compose

• Contains everything needed for our app

• Brings up our containers

• Creates the appropriate network

• Checked in with the rest of our code

Page 18: Introduction to Kubernetes - bolbeck.com

Demo roadmap

✔ Run app with Docker

➡ Write Kubernetes manifests

➡ Deploy to Kubernetes in Minikube

• Sidecar deployments

• Multi-environment manifests

Page 19: Introduction to Kubernetes - bolbeck.com

Kubernetes manifests

• Docker-compose defined our app with 3 services

• For K8s, we need to map those to multiple resource manifests:

• Deployments

• Services

• Persistent Volumes

• ConfigMaps

Page 20: Introduction to Kubernetes - bolbeck.com

Manual manifest creation

Page 21: Introduction to Kubernetes - bolbeck.com

Generating Kubernetes manifests

• Kompose generates manifests automagically!

!

• Based on dockercompose file

• Out of the box, generation gets you 90% there

• Run: kompose -f <path_to_dokercompose_file> convert

• Get Kompose at kompose.io

Page 22: Introduction to Kubernetes - bolbeck.com

Our app in K8s

• Application running:

• One container per Pod

• Network communication

• Accessible via browser

• Scaled up and down

• Is that where we want our Redis cache ?

Page 23: Introduction to Kubernetes - bolbeck.com

Demo roadmap

✔ Run app with Docker

✔ Write Kubernetes manifests

✔ Deploy to Kubernetes in Minikube

➡ Sidecar deployments

• Multi-environment manifests

Page 24: Introduction to Kubernetes - bolbeck.com

Caching as a sidecar

• Sidecar: provides additional functionality to main container

• Advantage: Treated as a local resource

• Disadvantage: Containers cannot be individually managed

• What we'll do:

• Remove our Redis deployment & service

• Add Redis to our Node deployment

• Change how Node discovers Redis

Page 25: Introduction to Kubernetes - bolbeck.com

Demo roadmap

✔ Run app with Docker

✔ Write Kubernetes manifests

✔ Deploy to Kubernetes in Minikube

✔ Sidecar deployments

➡ Multi-environment manifests

Page 26: Introduction to Kubernetes - bolbeck.com

Maintain manifest copies

Page 27: Introduction to Kubernetes - bolbeck.com

Kustomize

• YAML customization

• Merges YAML files

• Eases multi-configuration manifests maintenance

• Usage, either:

• Built-in as kubectl apply -k and kubectl kustomize

• Latest binary from Kustomize.io

Page 28: Introduction to Kubernetes - bolbeck.com

Demo roadmap

✔ Run app with Docker

✔ Write Kubernetes manifests

✔ Deploy to Kubernetes in Minikube

✔ Sidecar deployments

✔ Using secrets

✔ Multi-environment manifests

Page 29: Introduction to Kubernetes - bolbeck.com

K8s resources at a glance

Page 30: Introduction to Kubernetes - bolbeck.com

Rich ecosystem

Page 31: Introduction to Kubernetes - bolbeck.com

Key takeaways

Page 32: Introduction to Kubernetes - bolbeck.com

Questions ?

Thanks to the CWIT Conference & all the sponsors

Page 33: Introduction to Kubernetes - bolbeck.com

Appendix