using kubernetes to lose your fear of using containers
TRANSCRIPT
![Page 1: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/1.jpg)
Using kubernetes to loseyour fear of using containers
Jose Fuentes - [email protected]
Toolchain Engineer
@_jsfuentes
![Page 2: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/2.jpg)
Kubernetes
- Run containers on a cluster
- Automatic deployment
- Scaling
- Designed for failure
Health checking
And other cool features
Manage containerized application
Load balancing
Rolling updates
Replication
![Page 3: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/3.jpg)
Kubernetes
- Run containers on a cluster
- Automatic deployment
- Scaling
- Designed for failure
Health checking
And other cool features
Manage containerized application
Load balancing
Rolling updates
Replication
Implies a contract with the applicationImplies a contract with the application
![Page 4: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/4.jpg)
It sounds interesting. Tell me more.
- Must-know concepts for understanding kubernetes
- How my app should be to take advantage of all the features
- And some other interesting things for operating apps with k8s
log management debugging
health checking failure recovery
monitoring metering
updating
![Page 5: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/5.jpg)
Must-know concepts
![Page 6: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/6.jpg)
Architecturekubectl
Master
Controller Manager
Scheduler
etcd
Kubernetes APIMinion
docker engine
pod
kube-proxykubelet
pod
Minion
docker engine
pod
kube-proxykubelet
pod
firewall/loadbalancer/
proxy
Top view
![Page 7: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/7.jpg)
Minion 1- Collection containers
- Unit of scheduling and replication
- Ephemeral, not durable
- They’re replaced, not resurrected
- Containers in the same pod share:- PIDs- Network- Hostname
Kubernetes Master
Pod Container A Container B
Minion 2
Minion 1
Pod PodContainer C Container D
ComponentsPods
![Page 8: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/8.jpg)
-
-
-
-
Services Types
You can’t communicate with pods directly
ComponentsServices
services allows to route traffic to a set of pods
http://railsapp:3000
Minion 1
kube-proxy
pod
Minion 2
kube-proxy
pod
serviceCloud ProviderLoadBalancer
![Page 9: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/9.jpg)
-
-
-
-
Services Types
You can’t communicate with pods directly
ComponentsServices
services allows to route traffic to a set of pods
Minion 1
kube-proxy
pod
Minion 2
kube-proxy
pod
http://minion1:3000 http://minion2:3000
![Page 10: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/10.jpg)
-
-
-
-
Services Types
You can’t communicate with pods directly
ComponentsServices
services allows to route traffic to a set of pods
Minion 1
kube-proxy
pod
Minion 2
kube-proxy
pod
serviceCloud ProviderLoadBalancer
http://<public IP>
![Page 11: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/11.jpg)
-
-
-
-
Services Types
You can’t communicate with pods directly
ComponentsServices
services allows to route traffic to a set of podsExternalName
external.service.com
internalname
![Page 12: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/12.jpg)
- Arbitrary metadata attached to any object
- key-value pairs
- Relevant attributes for users
- Allows to organize objects in the cluster
Labels
Selectors
- Identify a set of objects based on labels values
app: myapprole: webbranch: prod
app: myapprole: dbbranch: prod
app: myapprole: webbranch: dev
app: myapprole: dbbranch: dev
branch == prod branch == dev
Labels and selectors
![Page 13: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/13.jpg)
ExampleServiceLoadBalancer
Pod
:80
Containerweb
:3000
ServiceClusterIP
Pod
Containermongo
:27017
:27017
![Page 14: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/14.jpg)
ExampleServiceLoadBalancer
Pod
:80
Containerweb
:3000
ServiceClusterIP
Pod
Containermongo
:27017
:27017
![Page 15: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/15.jpg)
CLI and UI
![Page 16: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/16.jpg)
- Manage several clusters and contexts
- Get cluster info: nodes, pods, services, deployments
- Deploy/delete stuff
- Scale up/down (replicas)
- Interact with containers
- See logs
- Create tunnels (port forwarding)
Kubectl CLI http://kubernetes.io/docs/user-guide/docker-cli-to-kubectl/
![Page 17: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/17.jpg)
Kubectl UI (dashboard) http://kubernetes.io/docs/user-guide/ui/
It runs in a pod!
![Page 18: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/18.jpg)
How an app should be to work well on k8s
![Page 19: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/19.jpg)
Let me tell you a secret...
![Page 20: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/20.jpg)
Kubernetes is not for everybody
![Page 21: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/21.jpg)
WishlistRestart should not be a pain
Your app is gonna be restarted often, so… stay prepared for that
- Start fast
- Don't cook assets at boot time
- Don't lose data on reboots
![Page 22: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/22.jpg)
WishlistData should be separated
Your app should be stateless.
The state should be stored apart.
uploaded files
sessions info
plugins
jobs
Oh man, that's easy. I mount a volume for my mariaDB and I am done.
It is not just the DB
![Page 23: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/23.jpg)
WishlistData schema compatible across versions
- That's not possible...- Well… at least do changes in a clever way
- Temporary maintain datastore compatible with two versions
- B/C changes
- Intermediate migrations
- Make logic to adapt API requests to the new format
![Page 24: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/24.jpg)
Example: Drupal blog
Database
Web server
Drupal php code v8.1 plugin
Web server
Drupal php code v8.2
Web server
Drupal php code v8.1 plugin
![Page 25: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/25.jpg)
Example: Drupal blog
Database
Web server
Drupal php code v8.1
Web server
Drupal php code v8.2
External volume
Web server
Drupal php code v8.1
plugin
![Page 26: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/26.jpg)
Underlying infrastructure
![Page 27: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/27.jpg)
A pet server
-You instantiated it time ago
-Then you manually installed thing you needed there
-You ssh it often because you like to manually check things there
-Eventually you go there and do some manual work to install
something
-Now you have an adorable pet that you really worry about
because it's something unique
![Page 28: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/28.jpg)
We want cattle servers
They are almost identicalEasily replaceable
DON'T SSH
![Page 29: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/29.jpg)
Manos a la obra!
![Page 30: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/30.jpg)
Our app
Containerweb
:3000
Containermongo
:27017
josefuentes/todolist docker build + docker push
bitnami/mongodb
Container images
![Page 31: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/31.jpg)
Our appDeployment info for kubernetes Service
LoadBalancer
Pod
:80
Containerweb
:3000
ServiceClusterIP
Pod
Containermongo
:27017
:27017
- Be aware of your app limitations
tier=web
tier=db
- Be tidy, use labels
- Be precise, set probes
replicas high availability configs
info stored in host
- If you know very well your app, limit the resources
![Page 32: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/32.jpg)
DebugGimme a shell!!!
List the pods
Use exec
kubectl get pods
kubectl exec -ti <mypod> -c <container> bash
![Page 33: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/33.jpg)
DebugSee logs
Use logskubectl logs <mypod> -c <container>
TIP: use -fkubectl logs -f <mypod> -c <container>
![Page 34: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/34.jpg)
DebugForward a port
Use logskubectl logs <mypod> -c <container>
TIP: use -fkubectl port-forward <mypod> [local_port:]remote_port
![Page 36: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/36.jpg)
Failure recovery
Inside pods -> restart policies
In machines -> pods reallocation
![Page 37: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/37.jpg)
PodContainer 1 Container 2
RestartPolicy: Always
PodContainer 2Container 1
PodContainer 2Container 1
PodContainer 1 Container 2
RestartPolicy: Never
PodContainer 2Container 1
PodContainer 2Container 1
Failed
Failure recovery
![Page 38: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/38.jpg)
PodContainer 1 Container 2
PodContainer 2Container 1
PodContainer 2Container 1
PodContainer 2Container 1
Successful
RestartPolicy: OnFailure
Failure recovery
![Page 39: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/39.jpg)
PodContainer 1 Container 2
PodContainer 2Container 1
PodContainer 2Container 1
Failed
PodContainer 2Container 1
Successful
RestartPolicy: Never
Failure recovery
![Page 40: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/40.jpg)
Scalereplicas
Several instances of a pod
- Same configuration
- Normally on different machines
- LoadBalancing
- Better redundancy
![Page 41: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/41.jpg)
Scalereplicas
There are many ways of scaling your app.
It is important how do you design your pods
Pod
Apache Express
Pod
mongoDBServiceDB
![Page 42: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/42.jpg)
Scalereplicas
There are many ways of scaling your app.
It is important how do you design your pods
Pod
mongoDBServiceDB
Pod
Apache Express
Pod
Apache Express
![Page 43: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/43.jpg)
Scalereplicas
There are many ways of scaling your app.
It is important how do you design your pods
Pod
mongoDBServiceDB
Pod
Express
Pod
Apache
Pod
Apache
![Page 44: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/44.jpg)
Advanced log monitoring
http://kubernetes.io/docs/getting-started-guides/logging-elasticsearch/
Pods are ephemeral -> logs are not going to be there forever
Solution -> log live ingestion
Pod
![Page 45: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/45.jpg)
Podversion=1
Podversion=1
Podversion=1
Podversion=1
ServiceLoadBalancer
Podversion=2
Podversion=2
$ kubectl set image deploy <your deploy> <container>=<image>
Rolling out new features
![Page 46: Using kubernetes to lose your fear of using containers](https://reader030.vdocuments.us/reader030/viewer/2022021502/58f12d451a28aba9358b45fb/html5/thumbnails/46.jpg)
Thank You