Repository navigation
Kubernetes
- Kubernetes for the absolute beginners course
- Certified Kubernetes Administrator Course
- Certified Kubernetes Application Developer Course
Kubernetes:
- Kubernetes Overview
- Containers- Docker
- Container Orchestration?
- Demo - Setup Kubernetes
- Kubernetes Concepts - PODs|ReplicaSets| Deployment|Services
- Networking in Kubernetes
- Kubernetes Management - Kubectl
- Kubernetes Definition Files- YAML
- Kubernetes on Cloud - AWS/GCP
Kubernetes is supported on any cloud platform, and supports hosting enhanced and complext applications on various kinds of architecture that makes it a vast and complex technology.
Important Terms: Containers, Yaml files, applications, Ingress, Installation, Storage, ReplicaSets, Deployment, Resources,Servies, PODS, Logging, PVolumes Claims, Taints & Tokens, Virtual Box, Federation, Jobs, Networking, Storage, Administration, Stateful Sets, Config Maps, Persistent Volumes, Security, Configuration, Load balancing, Autoscaling
built by google based on their experience running containers in production. opensource project and one of the best and most popular container orchestration technology out there
To understand kubernetes we need to understand Container+Orchestration
Docker:
-
Hardware Infrastructure
-
OS
-
Libraries + Depdendencies
-
Compatibility/Dependency
-
Long setup time
-
Different Dev/Test/Prod environment
Kubernetes:
-----------------
Kubernetes and the cloud native ecosystem:
K8s or Piolot or helmsman
K8s is written in Go
K8s can run on on-prem/public cloud/ hybrid
what are containers?
k8s is container orchestrator system
containers build the code and run within them
before containers we used to run on vms.
container advatages:
portable
uses less cpu, memory and saving money
self contained can spun up and down
quick replication and elastically scaleup and down
image- a container image is a file with executable code that can run as container
container registry- a database that stores container images, these images can be available to the public or private for those people or service accounts with permission
examples:
Docker hub
Quay
Google container registry
Docker alternatives:
podman
containerd
rkt
LXD
what is cloud native?
Agile
Devops
Cloud Native
kubernetes is a cloud native technology
cloud native technology empower organizations to build and run scalable applications in modern dynamic environment such as public, private, hybrid clouds. Containers, service meshes, microservices, immmutable infrastructure and declarative APIs exemplify this approach
A container requires a container engine to be installed on any operating system on which it is expected to work.
One goal of cloud native technologies is to increase the speed of application deployments.
Other goals include making applications highly available, scalable, and portable across environments.
What assumption is at the foundation of cloud native technology?
It is good to remove silos between ops teams and software development teams.
Correct
By removing these silos, cloud technology can help expedite code pushes to production.
Which statement is true regarding Kubernetes?
Kubernetes is an open-source system and has a large active body of developers.
Kubernetes is the Greek word for helmsman of a ship. Why did the creators of the project choose this name?
Kubernetes oversees a set of servers and decides where to deploy containerized applications, when to scale up and down the number of application replicas, and what to do when an application or server stops working.
to create cluster using minikube:
minikube start
difference between minikube and kubectl
minikube helps to create cluster from scratch
where as kubectl control lets you interact with your cluster
to get cluster info:
kubectl cluster-info
to get nodes:
kubectl get nodes
to see namespaces:
kubectl get namespaces
//namespaces are a way to isolate and manage applications and services that you want to remain second
to see pods and services:
kubectl get pods -A
//-A is to see the pods in all namespaces
these pods are how containers run in the kubernetes
these pods are the softwares to run a kubernetes cluster itself
to see services:
kubectl get services -A
//services act as LB within the cluster and direct traffic to pods
//this are the things that are setup by default in the cluster
Docker Desktop installs the container engine required by Kubernetes.
Application deployment
----------------------
Infrastructure as Code(IaC)
GitOps
these two approaches are often paired with kubernetes
in kubernetes setting up infra with code and preparing yourself to deploy changes through GitOps workflow require that you can save the desired state of your cluster in a set of files
that you manage with a source control system like Git
In kubernetes the commonly used format for the files is Yaml mainfests
Create a namespace:
kubernetes namespaces let you isolate and organize workloads
kubernetes mainfest for namespace:
---
apiVersion: v1
kind: Namespace
metadata:
name: development
executing this mainfest:
kubectl apply -f namespace.yaml
As kubernetes mainfest are written in yaml it is possible to define multiple resources in one file by separting the by ---
to delete namespaces:
kubectl delete -f namespace.yaml
Deploy an application in namespace:
kubectl get ns
kubectl apply -f deployment.yaml
kubectl get deployments -n development
kubectl get pods -n development
to delete a pod
kubectl delete pod pod_name -n namespace
kubectl delete pod pod-info-deployment-757cb75bbb-5rh8v -n development
check health of a pod by looking at event logs
kubectl get pods -n development
kubectl describe pod pod-info-deployment-757cb75bbb-68hl9
-n development
//event logs can be found at the end of describe of pod
kubectl apply -f busybox.yaml
kubectl get pods -n development -o wide
kubectl get pods
kubectl exec -it busybox-6b95744666-lmhnl -- /bin/sh
wget ip:port
wget 10.244.0.3:3000
how do you test your app which is not exposed to internet how to check?
spinup a busybox pod
find the pod ip and use wget to make a get request
this way we can verify our application is working
verifying application logs
kubectl get pods -n development
kubectl logs pod_name -n namespace
kubectl logs pod-info-deployment-757cb75bbb-68hl9 -n development
Using the describe pod command, what will the event log show for a pod that has been running for a long time?
If a pod has been running for a while, Kubernetes will assume it is healthy and not show its events.
Which kubectl command can you use to list all the pods in a specific namespace?
kubectl get pods -n mynamespace
In the following command structure that connects you to a BusyBox shell, what should you set for arg2?
kubectl exec arg1 arg2 arg3
the name of the BusyBox pod
What will be the outcome of the following command?
kubectl get pods
All pods in the default namespace will be listed.
Correct
With no namespace specified, the command will result in all the pods in the default namespace being listed.
Pod A with an IP address of 172.17.0.3 is running a web server. On pod B on the cluster, running wget 172.17.0.3 results in a refused connection. What is one immediate thing to check?
Pod A is exposing port 80.
Correct
Pod A should expose the port that the "wget" command is trying to call (defaulting to 80).
What is the syntax issue in the following YAML file?
items:
- bananas
- tomatoes
The indentation is wrong.
Correct
Nested items must be indented.
Which character or sequence of characters will you use in YAML to represent a sequence?
-
What additional information will show when the -o wide option is added to the kubectl get pods command?
IP address
Correct
The IP address will show for all listed pods.
Which path in the deployment YAML file specifies the number of instances to run?
spec -> replicas
What represents a valid namespace YAML?
---
apiVersion: v1
kind: Namespace
metadata:
name: mynamespace
What is the immediate parent of the following line?
- containerPort: 8080
ports:
Complex Application deployment:
kubernetes service is a load balancer service which directs traffic from internet to kubernetes pods.
a load balancer services has a public and static ip address.
lb should be public and static because pods ip address change frequently but service ip needs to remain the same
---
apiVersion: v1
kind: Service
metadata:
name: demo-service
namespace: development
spec:
selector:
app: pod-info
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
minikube tunnel
kubectl apply -f service.yaml
kubectl get services -n development
kubectl apply -f deployment.yaml
next step is to have selector map and returning the service to which it should send traffic to any pods with the label app: pod-info
kubectl delete -f file.yaml
kubectl delete -f busybox.yaml
kubectl delete -f deployment.yaml
kubectl delete -f quote.yaml
kubectl delete -f service.yaml
kubectl delete -f namespace.yaml
make sure you delete the namespace last because it will destroy anything inside of it
#delete minikube cluster
minikube delete
Your deployment YAML has the following configuration. What should your service YAML include so traffic is directed properly?
metadata:
labels:
app: pod-info
->
spec:
selector:
app: pod-info
Correct
What is not a type of service that Kubernetes offers?
AddressPool
Correct
AddressPool is not a service type that Kubernetes supports.
these are the type of service that kubernetes offers:
ClusterIP
LoadBalancer
NodePort
The term "resources" refers to the available bandwidth and memory on a worker node.
false
In a deployment YAML file, what is the immediate parent under which the resource request and limit specifications should be placed?
In a deployment YAML file, what is the immediate parent under which the resource request and limit specifications should be placed?
Since the resources apply to a container, they should be specified under the container's block
In the context of resource requests and limits to a pod, what do resources refer to?
available CPU and memory on the worker node
What will the following command do?
minikube delete
Delete the entire minikube cluster.
Correct
This command will delete the entire minikube cluster.
How would you delete a Kubernetes deployment created with a YAML manifest called api.yaml?
kubectl delete -f api.yaml
When you want someone to access an application deployed in your Kubernetes cluster, you will set up a Kubernetes _____ Service
LoadBalancer
Correct
Kubernetes Architecture:
Kubernetes control plane-
cluster - instance of kubernetes
control plane
worker node
Kube API Server - expose kubenetes API
-pods, deployments, and the horizontal pod autoscaler have API endpoints
-kubernetes API has a REST interface
-kubectl and kubeadm are CLI tools to communicate with kubernetes API via HTTP requests
to see all kubernetes resources:
kubectl api-resources
kubectl get pods -n kube-system
etcd: opensource hightly available key-value store, it saves all data about the cluster
kubectl logs etcd-minikube -n kube-system | jq
kube-scheduler
kube-controller-manager: checks status of pods
cloud controller manager: lets you connect the cloud provider's api, so that we can use cloud resources from AWS, GCP, azuer or any public cloud
Kubernetes worker nodes:
most kubernetes run with 3 pods
each pod has 3 parts:
kubelet:
- An agent that runs on every worker node
- makes sure that containers in a pod are runnig and healthy
- communicates directly with the api-server in the control plane
container runtime
- a kubelet assigned to new pod starts a container using container runtime interface(CRI)
- CRI enables the kubelet to create containers with the engines:
Containerd
CRI-O
Kata Containers
AWS Firecracker
kube-proxy:
makes sure pods and services can communicate
each kubeproxy communicates directly with kube-apiserver
Advanced Topics:
-Replicas
-No-downtime upgrades
Deamonset
one pod per node
background processes
Job
-runs until completion
-deletes pod
Running stateful workloads
kubernetes security