Kubernetes Basics

Preview:

Citation preview

kubernetes

THE NEED FOR CONTAINER ORCHESTRATION Docker packaging, deploying and running containerized application applications are independent of the underlying OS architecture.

Docker itself can be used to manage a few containers running on a fewer machines. Production applications deploy containers on a large scale on hundreds of machines.

THE NEED FOR CONTAINER ORCHESTRATION

PHYSICAL INFRASTRUCURE

VM VM VM VMVM VM VMVM

CLUSTER CLUSTER

CLUSTERCLUSTERCLUSTER

CLUSTER MANAGER

WHAT IS KUBERNETES A subset of an internal Google project called Borg. Decouples application from machines through containers. Maintains and tracks the global view of the cluster. Distributed architecture with master and multiple worker nodes. Developed in Go language. Automate the scaling and distribution of applications.

K8S FEATURES Horizontal scaling – with command or based on CPU usage. Self-healing – restart containers that fail or don`t respond to health check. Replaces and reschedules containers when nodes die. Automating binpacking – placing the containers based on their resource requirements thus saving system resource. Automated rollouts and rollbacks - If something goes wrong, Kubernetes will rollback the changes. Storage orchestration – mount the storage system of your choice from local storage or AWS or from a network storage system.

KUBERNETES ARCHITECTURE

XML file

JSON file

YAML file

KUBERNETES COMPONENTS Master - coordinates the cluster Cluster - set of physical or virtual machines and other infrastructure resources used by Kubernetes to run your applications. Nodes – hosts that run kubernetes applications. Pod - a co-located group of containers and volumes. Unit of deployment. Label -  a key/value pair for identification. Replication Controller – ensures/maintains availability and scalability. etcd – maintains state.

CREATING A CLUSTER A k8s cluster consists of two types of resources The Master coordinates the clusterNodes are the workers that runs application.The nodes communicate with the master using the KubernetesAPI, which the master exposes.

CREATE A DEPLOYMENT A Deployment is responsible for creating and updating instances of application. The Deployment controller replaces an instance if the Node hosting it goes down or it is deleted.

PODS AND NODES A Pod is a group of one or more application containers and includes shared storage (volumes), IP address and information about how to run them.

PODS AND NODES Every Kubernetes Node runs at least:Kubelet, a process responsible for communication between the Kubernetes Master and the Nodes

A container runtime (like Docker, rkt).

SERVICES Provides external access to a single or group of pods.

SCALING

BASIC COMMANDS Clusterminikube startkubectl cluster-infokubectl get nodes

Deploymentkubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080

kubectl get deployments Pods kubectl get podskubectl describe podskubectl proxy

BASIC COMMANDS Pods export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')

echo Name of the Pod: $POD_NAMEkubectl logs $POD_NAMEkubectl exec -ti $POD_NAME bash

Serviceskubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080kubectl get serviceskubectl describe services/kubernetes-bootcampexport NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') echo NODE_PORT=$NODE_PORT

minikube service kubernetes-bootcamp

BASIC COMMANDS Scalingkubectl scale deployments/kubernetes-bootcamp --replicas=4kubectl get deploymentskubectl get pods -o wide

Updating image kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

minikube service kubernetes-bootcampkubectl get pods

Recommended