SlideShare una empresa de Scribd logo
1 de 82
Descargar para leer sin conexión
S1 Hands-On Introduction to
Kubernetes
at in SF
Sunday, October 29th 9:00 am–12:30 pm
#LISA17
bit.ly/lisa17-k8s
presented by , Developer Advocate at Red Hat@ryanj
Administration
1.
2.
3.
4.
5.
Introduction
Workshop Setup
Kubernetes Basics
Learn five K8s Primitives
Kubernetes Architecture
Local Development with
Minikube
Wrap-up
Intro Survey / Who are you?
1. Are you doing anything with containers today?
2. Do you have any experience using Kubernetes?
3. Do you consider yourself to be basically proficient with the
kubectl cli tool?
4. Can you name five basic primitives or resource types?
5. Can you name five architectural components provided by
Kubernetes?
LISA17 S1 Training Prep
Bring a laptop with the following items pre-installed:
1.
2.
3.
4.
kubectl
minikube
docker
git
Install kubectl
Installation on linux/amd64:
Installation on macOS:
For other platforms, consult the o icial
To verify kubectl availability, try running:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s
kubectl setup guide
kubectl help
Install minikube
Installation on linux/amd64:
Installation on macOS:
For other platforms, see the
Optionally, customize your cluster's memory or cpu allocation:
to verify minikube availability:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/min
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/min
minikube release notes
minikube config set memory 4096
minikube config set cpus 2
minikube version
Minikube Basics
minikube provides an easy way to run Kubernetes locally:
When you are done, halt the VM to free up system resources:
Need a fresh start? Delete your VM instance with:
minikube start
minikube stop
minikube delete
Minikube troubleshooting
If your minikube environment does not boot correctly:
1. Minikube requires an OS virtualization back-end
2. Most OSes include some support for virtualization
3. You can use the flag to select a specific virt
provider
Check the project for more information about
Still stuck? Consider signing up for OpenShi Starter or GKE:
bit.ly/k8s-gcloud
--vm-driver
minikube start --vm-driver=virtualbox
README supported
virtualization plugins
Install docker
Download and install a binary from
Or, use a package manager to install:
To verify docker availability:
To , run:
the docker store
brew install docker
docker version
reference minikube's docker daemon from your host
eval $(minikube docker-env)
Install git
Install git using the instructions here:
To verify git availability, run:
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
git version
Ready?
Verify that your local Kubernetes environment is ready by running:
The output should include your kubectl version info, and the
release version of the kubernetes API server (when available)
kubectl version
Let's Go!
Kubernetes Command-Line Basics
with kubectl
Why Kubernetes?
Kubernetes is...
1. An open source platform for running container-based distributed
solutions, featuring a modular, HA systems architecture
2. The best way to actively manage distributed solutions at scale,
based on years of industry expertise (Google-scale experience)
3. An extensible distributed-solutions modeling language with a
huge community following
4. A multi-vendor e ort to eliminate cloud lock-in through the
adoption of "cloud native" solutions (capable of runnning on any
infrastructure)
Kubernetes provides…
An API
API object primitives include the following attributes:
*mostly true
kind
apiVersion
metadata
spec
status
Basic K8s Terminology
1.
2.
3.
4.
5.
node
pod
service
deployment
replicaSet
Node
A node is a host machine (physical or virtual) where containerized
processes run.
Node activity is managed via one or more Master instances.
Try using kubectl to list resources by type:
Request the same info, but output the results as structured yaml:
Fetch an individual resource by type/id, output as json:
View human-readable API output:
kubectl get nodes
kubectl get nodes -o yaml
kubectl get node/minikube -o json
kubectl describe node/minikube
Observations:
Designed to exist on multiple machines (distributed
system)
high availability of nodes
platform scale out
The API ambidextriously supports both json and yaml
Pod
A group of one or more co-located containers. Pods represent your
minimum increment of scale.
"Pods Scale together, and they Fail together"
@theSteve0
List resources by type:
Create a new resource based on a json object specification:
List resources by type:
Fetch a resource by type and id, output the results as yaml:
Notice any changes?
kubectl get pods
curl https://raw.githubusercontent.com/ryanj/metrics-k8s/master/pod.json
kubectl create -f https://raw.githubusercontent.com/ryanj/metrics-k8s/master/
kubectl get pods
kubectl get pod metrics-k8s -o yaml
Observations:
pods are scheduled to be run on nodes
asyncronous fulfilment of requests
declarative specifications
automatic health checks, lifecycle management for containers
(processes)
Service
Services (svc) establish a single endpoint for a collection of
replicated pods, distributing inbound tra ic based on label
selectors
In our K8s modeling language they represent a load balancer. Their
implementation o en varies per cloud provider
Contacting your App
Expose the pod by creating a new service (or "loadbalancer"):
Contact your newly-exposed pod using the associated service id:
Schedule a pod to be deleted:
Contact the related service. What happens?:
Delete the service:
kubectl expose pod/metrics-k8s --port 2015 --type=NodePort
minikube service metrics-k8s
kubectl delete pod metrics-k8s
minikube service metrics-k8s
kubectl delete service metrics-k8s
Observations:
"service" basically means "loadbalancer"
Pods and Services exist independently, have disjoint
lifecycles
Deployment
A deployment helps you specify container runtime requirements
(in terms of pods)
Create a specification for your deployment:
View the generated deployment spec file:
Bug?:You may need to edit this file, adding "---" (on it's own line)
between resource 1 and resource 2 for a workaround.
Can you think of another way to fix this issue? json compatible?
kubectl run metrics-k8s --image=quay.io/ryanj/metrics-k8s 
--expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }'
--dry-run -o yaml > deployment.yaml
cat deployment.yaml
Create a new resource based on your yaml specification:
List resources by type:
Connect to your new deployment via the associated service id:
kubectl create -f deployment.yaml
kubectl get po,svc
minikube service metrics-k8s
Replication
Scale up the metrics-k8s deployment to 3 replicas:
List pods:
kubectl scale deploy/metrics-k8s --replicas=3
kubectl get po
Edit deploy/metrics-k8s, setting spec.replicas to 5:
Save and quit. What happens?
kubectl edit deploy/metrics-k8s -o json
kubectl get pods
AutoRecovery
Watch for changes to pod resources:
In another terminal, delete several pods by id:
What happend? How many pods remain?
kubectl get pods --watch
kubectl delete pod $(kubectl get pods | grep ^metrics-k8s | cut -f1 -s -d' '
kubectl get pods
Observations:
Use the --dry-run flag to generate new resource
specifications
A deployment spec contains a pod spec
ReplicaSet
A replicaset provides replication and lifecycle management for
a specific image release
Watch deployments (leave this running until the 'cleanup' section):
View the current state of your deployment:
kubectl get deploy --watch
minikube service metrics-k8s
Rollouts
Update your deployment's image spec to rollout a new release:
Reload your browser to view the state of your deployment
kubectl set image deploy/metrics-k8s metrics-k8s=quay.io/ryanj/metrics-k8s:v1
kubectl get rs,deploy
Rollbacks
View the list of previous rollouts:
Rollback to the previous state:
Reload your browser to view the state of your deployment
kubectl rollout history deploy/metrics-k8s
kubectl rollout undo deployment metrics-k8s
Cleanup
Cleanup old resources if you don't plan to use them:
Close any remaining --watch listeners
kubectl delete service,deployment metrics-k8s
Observations:
The API allows for watch operations (in addition to get, set, list)
ReplicaSets provide lifecycle management for pod resources
Deployments create ReplicaSets to manage pod replication per
rollout (per change in podspec: image:tag, environment vars)
break 1
Kubernetes Architecture
adapted for minikube
Kubernetes is designed ...
1. for managing distributed solutions at scale, based on years of
industry expertise (Google-scale experience)
2. for high availabilty of the control plane and user workloads
(when using pod replication), avoiding most single points of
failure
3. with a modular control plane architecture, allowing many peices
to be replaced without disrupting workload availability
4. to persist all of it's internal platform state within an etcd
database
etcd
distributed key-value store
implements the RAFT consensus
protocol
CAP theorum
1. Consistency
2. Availability
3. Partition
tolerance
etcd is "CA"
Degraded Performance
Fault tolerance sizing chart:
play.etcd.io
play.etcd.io/play
Kubernetes API
gatekeeper for etcd (the only way to access the
db)
not required for pod uptime
API outage simulation
Example borrowed from
:
Brandon Philips' "Fire Drills" from OSCON
2016
https://github.com/philips/2016-OSCON-containers-at-scale-with-
Kubernetes#fire-drills
Create a pod and a service. Verify that the service is responding.
ssh into minikube, kill the control plane:
Use kubectl to list pods:
The API server is down!
Reload your service. Are your pods still available?
kubectl run metrics-k8s --image=quay.io/ryanj/metrics-k8s 
--expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }'
minikube service metrics-k8s
minikube ssh
ps aux | grep "localkube"
sudo killall localkube
logout
kubectl get pods
The connection to the server mycluster.example.com was refused - did you spec
Kubelet
Runs on each node, listens to the API for new items with a matching
NodeName
Kubernetes Scheduler
Assigns workloads to Node machines
Bypass the Scheduler
Create two pods:
View events:
Did both pods get scheduled? run?
kubectl create -f https://raw.githubusercontent.com/ryanj/metrics-k8s/master/
kubectl create -f https://gist.githubusercontent.com/ryanj/893e0ac5b3887674f8
kubectl get events
Kube DNS
Kube Proxy
CNI
flannel
canal
CRI
containerd
(docker)
cri-o
rkt
compatible with OCI image spec., runtime
K8s Controllers
Controllers work to regulate the declarative nature of the platform
state, reconsiling imbalances via a basic control loop
Kubernetes allows you to introduce your own custom controllers!
https://kubernetes.io/docs/admin/kube-controller-manager/
Architecture Diagram
Interaction Diagram
(copied from blog.docker.com)
break 2
Local Development
with
minikube
Kubernetes provides portable abstractions for working with
distributed solitions:
1. standardized packaging (containers, volumes,
pods)
2. load balancing (services)
3. scaling automation (replica sets)
Need any of these for local development?
Why run K8s locally?
As web development is increasingly being carried out using
container-based microservices:
1. ability to o er reproducible development environments
reduce onboarding time for new devs
2. minimize deltas between dev and prod environments
fewer surprises when promoting code leads to faster velocity
3. decentralize your release pipeline, allow CI test suites to be run
locally
provide functional / systems-integration feedback earlier in
the dev lifecycle
4. potenial for fully o line development
<expanding brain meme>
Local Development Checklist:
1. - show someone new how to run the :latest
release
2. - review changes and iterate on a solution
3. - build and deploy
4. - git push
onboarding
preview changes
test changes
promote changes
Onboarding
Onboarding - Yesterday's Jam
1. git clone https://github.com/ryanj/metrics-
k8s
2. cd metrics-k8s
3. npm install
4. npm start
Onboarding - Add K8s
Generate kubernetes deployment and service specifications,
both named metrics-review:
kubectl run metrics-review --image=quay.io/ryanj/metrics-k8s 
--expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }'
--dry-run -o yaml > metrics-review.yaml
Onboarding - deploy :latest
Test your generated spec:
Minikube users will be able to open the resulting service in their
browser by running:
kubectl create -f metrics-review.yaml
minikube service metrics-review
Preview Changes
Preview - local files
First, share your local clone of metrics-k8s with minikube:
minikube mount $(pwd):/var/www/html
Preview - hostPath
Next, produce a new deployment spec that includes (minimal)
support for live development workflows:
1. cp metrics-review.yaml metrics-
dev.yaml
2. replace metrics-review with metrics-dev
(global)
3. Add a hostPort volume to access your local repo:
spec:
containers:
- image: quay.io/ryanj/metrics-k8s
name: metrics-dev
ports:
- containerPort: 2015
resources: {}
+ volumeMounts:
+ - mountPath: /var/www/html
+ name: metrics-src
+ volumes:
+ - name: metrics-src
+ hostPath:
Preview
The resulting file should look just like the included
file from the metrics-k8s git repo.
Try launching it with:
metrics-
dev.yaml
kubectl create -f metrics-dev.yaml
Preview
Verify that any changes written to your local repo become
immediately visible when reloading your browser window:
1. view your latest
2. make a change to
index.html
3. reload your browser
minikube service metrics-dev
Test
Test - Rollout
1. Verify that
2. Run a build
3. Update metrics-review.yaml, setting the container
image to:
4. Apply the changes locally:
5. Check your latest before promoting:
your docker-env is configured for minikube
docker build . -t yourname/metrics-k8s:v1
yourname/metrics-k8s:v1
kubectl apply -f metrics-review.yaml
minikube service metrics-review
Promote Changes
Promoting Changes
1. git push?
2. send PR?
3. next steps TBD / handled by CI
suite
Wrap Up
Resources
1. Training materials to-go:
2. Home:
3. Docs:
4. Community:
5. eBook:
6. eBook:
7. eBook:
8. eBook:
bit.ly/k8s-workshops
kubernetes.io
K8s documentation
K8s Special Interest Groups (SIGs)
Kubernetes: Scheduling the Future at Cloud Scale
Docker Security: Using Containers Safely in
Production
Microservices vs. Service-Oriented Architecture
OpenShi for Developers
Exit Survey
1. Have you ever developed using containers?
2. Do you have any experience using Kubernetes?
3. Do you consider yourself to be basically proficient with the
kubectl cli tool?
4. Can you name five basic primitives or resource types?
5. Can you name five pieces of k8s architecture?
6. Are you prepared to onboard a new web dev?
Congratulations!
on completing the
[S1] Hands-on Intro to Kubernetes
tutorial at #LISA17 in SF
Please remember to complete your tutorial evaluation!
bit.ly/lisa17-k8s

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Kubernetes architecture
Kubernetes architectureKubernetes architecture
Kubernetes architecture
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
 
K8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals TrainingK8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals Training
 
GitOps and ArgoCD
GitOps and ArgoCDGitOps and ArgoCD
GitOps and ArgoCD
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
 
Kubernetes Concepts And Architecture Powerpoint Presentation Slides
Kubernetes Concepts And Architecture Powerpoint Presentation SlidesKubernetes Concepts And Architecture Powerpoint Presentation Slides
Kubernetes Concepts And Architecture Powerpoint Presentation Slides
 
Docker & kubernetes
Docker & kubernetesDocker & kubernetes
Docker & kubernetes
 
Docker in real life
Docker in real lifeDocker in real life
Docker in real life
 
Kubernetes Deployment Strategies
Kubernetes Deployment StrategiesKubernetes Deployment Strategies
Kubernetes Deployment Strategies
 
OpenShift-Technical-Overview.pdf
OpenShift-Technical-Overview.pdfOpenShift-Technical-Overview.pdf
OpenShift-Technical-Overview.pdf
 
Kubernetes Architecture
 Kubernetes Architecture Kubernetes Architecture
Kubernetes Architecture
 
Kubernetes CI/CD with Helm
Kubernetes CI/CD with HelmKubernetes CI/CD with Helm
Kubernetes CI/CD with Helm
 
Kubernetes
KubernetesKubernetes
Kubernetes
 

Similar a Hands-On Introduction to Kubernetes at LISA17

Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
Tobias Schneck
 

Similar a Hands-On Introduction to Kubernetes at LISA17 (20)

Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
Kubernetes extensibility
Kubernetes extensibilityKubernetes extensibility
Kubernetes extensibility
 
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
01 - VMUGIT - Lecce 2018 - Fabio Rapposelli, VMware
 
Kubernetes - Sailing a Sea of Containers
Kubernetes - Sailing a Sea of ContainersKubernetes - Sailing a Sea of Containers
Kubernetes - Sailing a Sea of Containers
 
A brief study on Kubernetes and its components
A brief study on Kubernetes and its componentsA brief study on Kubernetes and its components
A brief study on Kubernetes and its components
 
Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)
 
An Introduction to Kubernetes and Continuous Delivery Fundamentals
An Introduction to Kubernetes and Continuous Delivery FundamentalsAn Introduction to Kubernetes and Continuous Delivery Fundamentals
An Introduction to Kubernetes and Continuous Delivery Fundamentals
 
Deploying Windows Apps to Kubernetes with Draft and Helm
Deploying Windows Apps to Kubernetes with Draft and HelmDeploying Windows Apps to Kubernetes with Draft and Helm
Deploying Windows Apps to Kubernetes with Draft and Helm
 
Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_
 
Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...
Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...
Salvatore Incandela, Fabio Marinelli - Using Spinnaker to Create a Developmen...
 
Oscon 2017: Build your own container-based system with the Moby project
Oscon 2017: Build your own container-based system with the Moby projectOscon 2017: Build your own container-based system with the Moby project
Oscon 2017: Build your own container-based system with the Moby project
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307
 
OSS Japan 2019 service mesh bridging Kubernetes and legacy
OSS Japan 2019 service mesh bridging Kubernetes and legacyOSS Japan 2019 service mesh bridging Kubernetes and legacy
OSS Japan 2019 service mesh bridging Kubernetes and legacy
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB201904_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
 
Kubernetes workshop -_the_basics
Kubernetes workshop -_the_basicsKubernetes workshop -_the_basics
Kubernetes workshop -_the_basics
 
Introduction to Kubernetes.pdf
Introduction to Kubernetes.pdfIntroduction to Kubernetes.pdf
Introduction to Kubernetes.pdf
 
Kube Overview and Kube Conformance Certification OpenSource101 Raleigh
Kube Overview and Kube Conformance Certification OpenSource101 RaleighKube Overview and Kube Conformance Certification OpenSource101 Raleigh
Kube Overview and Kube Conformance Certification OpenSource101 Raleigh
 
Kubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionKubernetes Architecture and Introduction
Kubernetes Architecture and Introduction
 
Azure kubernetes service (aks) part 3
Azure kubernetes service (aks)   part 3Azure kubernetes service (aks)   part 3
Azure kubernetes service (aks) part 3
 
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Hands-On Introduction to Kubernetes at LISA17

  • 1. S1 Hands-On Introduction to Kubernetes at in SF Sunday, October 29th 9:00 am–12:30 pm #LISA17 bit.ly/lisa17-k8s
  • 2. presented by , Developer Advocate at Red Hat@ryanj
  • 3. Administration 1. 2. 3. 4. 5. Introduction Workshop Setup Kubernetes Basics Learn five K8s Primitives Kubernetes Architecture Local Development with Minikube Wrap-up
  • 4. Intro Survey / Who are you? 1. Are you doing anything with containers today? 2. Do you have any experience using Kubernetes? 3. Do you consider yourself to be basically proficient with the kubectl cli tool? 4. Can you name five basic primitives or resource types? 5. Can you name five architectural components provided by Kubernetes?
  • 5. LISA17 S1 Training Prep Bring a laptop with the following items pre-installed: 1. 2. 3. 4. kubectl minikube docker git
  • 6. Install kubectl Installation on linux/amd64: Installation on macOS: For other platforms, consult the o icial To verify kubectl availability, try running: curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s kubectl setup guide kubectl help
  • 7. Install minikube Installation on linux/amd64: Installation on macOS: For other platforms, see the Optionally, customize your cluster's memory or cpu allocation: to verify minikube availability: curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/min curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/min minikube release notes minikube config set memory 4096 minikube config set cpus 2 minikube version
  • 8. Minikube Basics minikube provides an easy way to run Kubernetes locally: When you are done, halt the VM to free up system resources: Need a fresh start? Delete your VM instance with: minikube start minikube stop minikube delete
  • 9. Minikube troubleshooting If your minikube environment does not boot correctly: 1. Minikube requires an OS virtualization back-end 2. Most OSes include some support for virtualization 3. You can use the flag to select a specific virt provider Check the project for more information about Still stuck? Consider signing up for OpenShi Starter or GKE: bit.ly/k8s-gcloud --vm-driver minikube start --vm-driver=virtualbox README supported virtualization plugins
  • 10. Install docker Download and install a binary from Or, use a package manager to install: To verify docker availability: To , run: the docker store brew install docker docker version reference minikube's docker daemon from your host eval $(minikube docker-env)
  • 11. Install git Install git using the instructions here: To verify git availability, run: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git git version
  • 12. Ready? Verify that your local Kubernetes environment is ready by running: The output should include your kubectl version info, and the release version of the kubernetes API server (when available) kubectl version
  • 16. Kubernetes is... 1. An open source platform for running container-based distributed solutions, featuring a modular, HA systems architecture 2. The best way to actively manage distributed solutions at scale, based on years of industry expertise (Google-scale experience) 3. An extensible distributed-solutions modeling language with a huge community following 4. A multi-vendor e ort to eliminate cloud lock-in through the adoption of "cloud native" solutions (capable of runnning on any infrastructure)
  • 17. Kubernetes provides… An API API object primitives include the following attributes: *mostly true kind apiVersion metadata spec status
  • 19. Node A node is a host machine (physical or virtual) where containerized processes run. Node activity is managed via one or more Master instances.
  • 20. Try using kubectl to list resources by type: Request the same info, but output the results as structured yaml: Fetch an individual resource by type/id, output as json: View human-readable API output: kubectl get nodes kubectl get nodes -o yaml kubectl get node/minikube -o json kubectl describe node/minikube
  • 21. Observations: Designed to exist on multiple machines (distributed system) high availability of nodes platform scale out The API ambidextriously supports both json and yaml
  • 22. Pod A group of one or more co-located containers. Pods represent your minimum increment of scale. "Pods Scale together, and they Fail together" @theSteve0
  • 23. List resources by type: Create a new resource based on a json object specification: List resources by type: Fetch a resource by type and id, output the results as yaml: Notice any changes? kubectl get pods curl https://raw.githubusercontent.com/ryanj/metrics-k8s/master/pod.json kubectl create -f https://raw.githubusercontent.com/ryanj/metrics-k8s/master/ kubectl get pods kubectl get pod metrics-k8s -o yaml
  • 24. Observations: pods are scheduled to be run on nodes asyncronous fulfilment of requests declarative specifications automatic health checks, lifecycle management for containers (processes)
  • 25. Service Services (svc) establish a single endpoint for a collection of replicated pods, distributing inbound tra ic based on label selectors In our K8s modeling language they represent a load balancer. Their implementation o en varies per cloud provider
  • 26. Contacting your App Expose the pod by creating a new service (or "loadbalancer"): Contact your newly-exposed pod using the associated service id: Schedule a pod to be deleted: Contact the related service. What happens?: Delete the service: kubectl expose pod/metrics-k8s --port 2015 --type=NodePort minikube service metrics-k8s kubectl delete pod metrics-k8s minikube service metrics-k8s kubectl delete service metrics-k8s
  • 27. Observations: "service" basically means "loadbalancer" Pods and Services exist independently, have disjoint lifecycles
  • 28. Deployment A deployment helps you specify container runtime requirements (in terms of pods)
  • 29. Create a specification for your deployment: View the generated deployment spec file: Bug?:You may need to edit this file, adding "---" (on it's own line) between resource 1 and resource 2 for a workaround. Can you think of another way to fix this issue? json compatible? kubectl run metrics-k8s --image=quay.io/ryanj/metrics-k8s --expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }' --dry-run -o yaml > deployment.yaml cat deployment.yaml
  • 30. Create a new resource based on your yaml specification: List resources by type: Connect to your new deployment via the associated service id: kubectl create -f deployment.yaml kubectl get po,svc minikube service metrics-k8s
  • 31. Replication Scale up the metrics-k8s deployment to 3 replicas: List pods: kubectl scale deploy/metrics-k8s --replicas=3 kubectl get po
  • 32. Edit deploy/metrics-k8s, setting spec.replicas to 5: Save and quit. What happens? kubectl edit deploy/metrics-k8s -o json kubectl get pods
  • 33. AutoRecovery Watch for changes to pod resources: In another terminal, delete several pods by id: What happend? How many pods remain? kubectl get pods --watch kubectl delete pod $(kubectl get pods | grep ^metrics-k8s | cut -f1 -s -d' ' kubectl get pods
  • 34. Observations: Use the --dry-run flag to generate new resource specifications A deployment spec contains a pod spec
  • 35. ReplicaSet A replicaset provides replication and lifecycle management for a specific image release
  • 36. Watch deployments (leave this running until the 'cleanup' section): View the current state of your deployment: kubectl get deploy --watch minikube service metrics-k8s
  • 37. Rollouts Update your deployment's image spec to rollout a new release: Reload your browser to view the state of your deployment kubectl set image deploy/metrics-k8s metrics-k8s=quay.io/ryanj/metrics-k8s:v1 kubectl get rs,deploy
  • 38. Rollbacks View the list of previous rollouts: Rollback to the previous state: Reload your browser to view the state of your deployment kubectl rollout history deploy/metrics-k8s kubectl rollout undo deployment metrics-k8s
  • 39. Cleanup Cleanup old resources if you don't plan to use them: Close any remaining --watch listeners kubectl delete service,deployment metrics-k8s
  • 40. Observations: The API allows for watch operations (in addition to get, set, list) ReplicaSets provide lifecycle management for pod resources Deployments create ReplicaSets to manage pod replication per rollout (per change in podspec: image:tag, environment vars)
  • 43. Kubernetes is designed ... 1. for managing distributed solutions at scale, based on years of industry expertise (Google-scale experience) 2. for high availabilty of the control plane and user workloads (when using pod replication), avoiding most single points of failure 3. with a modular control plane architecture, allowing many peices to be replaced without disrupting workload availability 4. to persist all of it's internal platform state within an etcd database
  • 44. etcd distributed key-value store implements the RAFT consensus protocol
  • 45. CAP theorum 1. Consistency 2. Availability 3. Partition tolerance etcd is "CA"
  • 48. Kubernetes API gatekeeper for etcd (the only way to access the db) not required for pod uptime
  • 49. API outage simulation Example borrowed from : Brandon Philips' "Fire Drills" from OSCON 2016 https://github.com/philips/2016-OSCON-containers-at-scale-with- Kubernetes#fire-drills
  • 50. Create a pod and a service. Verify that the service is responding. ssh into minikube, kill the control plane: Use kubectl to list pods: The API server is down! Reload your service. Are your pods still available? kubectl run metrics-k8s --image=quay.io/ryanj/metrics-k8s --expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }' minikube service metrics-k8s minikube ssh ps aux | grep "localkube" sudo killall localkube logout kubectl get pods The connection to the server mycluster.example.com was refused - did you spec
  • 51. Kubelet Runs on each node, listens to the API for new items with a matching NodeName
  • 53. Bypass the Scheduler Create two pods: View events: Did both pods get scheduled? run? kubectl create -f https://raw.githubusercontent.com/ryanj/metrics-k8s/master/ kubectl create -f https://gist.githubusercontent.com/ryanj/893e0ac5b3887674f8 kubectl get events
  • 58. K8s Controllers Controllers work to regulate the declarative nature of the platform state, reconsiling imbalances via a basic control loop Kubernetes allows you to introduce your own custom controllers! https://kubernetes.io/docs/admin/kube-controller-manager/
  • 63. Kubernetes provides portable abstractions for working with distributed solitions: 1. standardized packaging (containers, volumes, pods) 2. load balancing (services) 3. scaling automation (replica sets) Need any of these for local development?
  • 64. Why run K8s locally? As web development is increasingly being carried out using container-based microservices: 1. ability to o er reproducible development environments reduce onboarding time for new devs 2. minimize deltas between dev and prod environments fewer surprises when promoting code leads to faster velocity 3. decentralize your release pipeline, allow CI test suites to be run locally provide functional / systems-integration feedback earlier in the dev lifecycle 4. potenial for fully o line development <expanding brain meme>
  • 65. Local Development Checklist: 1. - show someone new how to run the :latest release 2. - review changes and iterate on a solution 3. - build and deploy 4. - git push onboarding preview changes test changes promote changes
  • 67. Onboarding - Yesterday's Jam 1. git clone https://github.com/ryanj/metrics- k8s 2. cd metrics-k8s 3. npm install 4. npm start
  • 68. Onboarding - Add K8s Generate kubernetes deployment and service specifications, both named metrics-review: kubectl run metrics-review --image=quay.io/ryanj/metrics-k8s --expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }' --dry-run -o yaml > metrics-review.yaml
  • 69. Onboarding - deploy :latest Test your generated spec: Minikube users will be able to open the resulting service in their browser by running: kubectl create -f metrics-review.yaml minikube service metrics-review
  • 71. Preview - local files First, share your local clone of metrics-k8s with minikube: minikube mount $(pwd):/var/www/html
  • 72. Preview - hostPath Next, produce a new deployment spec that includes (minimal) support for live development workflows: 1. cp metrics-review.yaml metrics- dev.yaml 2. replace metrics-review with metrics-dev (global) 3. Add a hostPort volume to access your local repo: spec: containers: - image: quay.io/ryanj/metrics-k8s name: metrics-dev ports: - containerPort: 2015 resources: {} + volumeMounts: + - mountPath: /var/www/html + name: metrics-src + volumes: + - name: metrics-src + hostPath:
  • 73. Preview The resulting file should look just like the included file from the metrics-k8s git repo. Try launching it with: metrics- dev.yaml kubectl create -f metrics-dev.yaml
  • 74. Preview Verify that any changes written to your local repo become immediately visible when reloading your browser window: 1. view your latest 2. make a change to index.html 3. reload your browser minikube service metrics-dev
  • 75. Test
  • 76. Test - Rollout 1. Verify that 2. Run a build 3. Update metrics-review.yaml, setting the container image to: 4. Apply the changes locally: 5. Check your latest before promoting: your docker-env is configured for minikube docker build . -t yourname/metrics-k8s:v1 yourname/metrics-k8s:v1 kubectl apply -f metrics-review.yaml minikube service metrics-review
  • 78. Promoting Changes 1. git push? 2. send PR? 3. next steps TBD / handled by CI suite
  • 80. Resources 1. Training materials to-go: 2. Home: 3. Docs: 4. Community: 5. eBook: 6. eBook: 7. eBook: 8. eBook: bit.ly/k8s-workshops kubernetes.io K8s documentation K8s Special Interest Groups (SIGs) Kubernetes: Scheduling the Future at Cloud Scale Docker Security: Using Containers Safely in Production Microservices vs. Service-Oriented Architecture OpenShi for Developers
  • 81. Exit Survey 1. Have you ever developed using containers? 2. Do you have any experience using Kubernetes? 3. Do you consider yourself to be basically proficient with the kubectl cli tool? 4. Can you name five basic primitives or resource types? 5. Can you name five pieces of k8s architecture? 6. Are you prepared to onboard a new web dev?
  • 82. Congratulations! on completing the [S1] Hands-on Intro to Kubernetes tutorial at #LISA17 in SF Please remember to complete your tutorial evaluation! bit.ly/lisa17-k8s