Kubernetes – 01- Getting Started

Objectives

  • The need for container orchestiration
  • Overview of Kubernetes
  • Setting up Kubernetes development environment
  • Deploying your first application
  • Summary
  1. The need for container orchestiration

-Containers are becoming the standard unit of deployment

-Each container image has

  • Code
  • Binaries
  • Configuration
  • Libraries
  • Frameworks
  • Runtime

-Developers and Operators love containers

-Docker has solved the problem of packaging , deploying and running containerized applications

-Docker has three key components

  • Container Engine
  • Registry
  • Tools

-Docker is great for managing a few containers running on fewer machines

-Production  applications deal with dozens of containers running on hundereds of machine

-The unit of deployment is changing from machine to a container

-Infrastructure has become immutable

-Emphasis on treating the datacenter as a large server (cluster)

-Tools are evolbing to manage the new datacenter infrastructure

  • Docker Swarm
  • Kubernetes
  • Mesosphere DS/OS

-Manage lifescycle of containerized applications running on production

-Automate the distribution of applications

-Ensure higher levels of utilization and effiency (daha yüksek kullanım ve verimlilik seviyelerini sağlamak)

*A DATACENTER IS NOT A COLLECTION OF COMPUTERS, A DATACENTER IS A COMPUTER

WHAT IS KUBERNETES

  • Kubernetes is inspired from an internal Google project caled Borg
  • Open source project managed by Linux Foundation
  • Unified API for deploying web applications, batch jobs, and databases
  • Decouples applications from machines through containers
  • Declarative approach to deploying applications
  • Automates application configuration through service discovery
  • Maintains and tracks the global view of cluster
  • APIs for deployment workflows
  •        Rolling updates,canary deploys, and blue green deployments

KUBERNETES ARCHITECTURE

-Master is responsible the making desicion

 

 

 

 

Advertisements

Kubernetes -06- Demo

 

https://github.com/apocoder/kubernetes-101

pip install -r requirements.txt

python app.py

curl localhost:5000

devpc:~ apocoder$ curl localhost:5000
Hello Container World! I have been seen 2 times.

Docker

cd Docker

docker-compose up

curl localhost:3000

Kubernetes

kubectl create -f db-pod.yml

 

devpc:Kubernetes apocoder$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-web-857d97b7cd-k754z 1/1 Running 0 5h
redis 1/1 Running 0 2m
web 0/1 ContainerCreating 0 14s

 

 

Kubernetes -05- Sample Application

Core Elements of Kubernetes

-Kubernetes Pod

  • Group of one or more containers that are always co-located
  • co-scheduled,and run in a shared context
  • Containers in the same pod have the hostname
  • Each pod is isolated by
    • Process Id (PID) namespace
    • Network namespace
    • Interprocess Communication (IPC) namespace
    • Unix Time Sharing (UTS) namespace
  • Alternative to a VM with multiliple process

-Labels & Selectors

  • Key/Value pairs associated with Kubernetes objects
  • Used to organize and select subsets objects
  • Attached to objects at creation time but modified any time

For example you want to load balance two pods  you want to change the trafic you can assing to metadata -> label and you can see which pod capture current traffic

Deploying a Pod

We have to define Pod in yaml,

Master will take theese two definations understands to constrains resoure allocation

Node will pass the pod definition, pull the image from registery, and reports the health back to the master,when the ready kubernetes will take next action

Services provides to communication accross other pods or objects ,expose the ports internal external,

 

 

Kubernetes -04- Architecture

Objectives

  • A closer look at Kubernetes cluster
  • Master components
  • Node components
  • Pods
  • Labels & Selectors
  • Replication Controllers
  • Services

Kubernetes has two diffrent layers Master and Nodes

Api Server -> kubectl , kubernetes dashboard

Scheduler->responsible for physically share cpu and resources

Controller-> health of the entire cluster , cordinator, nodes are up and running

Etcd -> distributed key value db, (developed by Coreos),stores to current cluster state

kube-proxy -> core networking component

kubelet -> is the agent , responsible is reporting to master (health)

Supervisord-> ensure docker and kubelet run all the time

fluentd-> responsible the managing the logs ,  talking to logging mechanism

pod -> A pod is a group of one or more containers

 

 

Kubernetes -03- Terminology & Deployment

Kubernetes Terminology

  • Nodes
    • Hosts that run Kubernetes applications
  • Containers
    • Units of packaging
  • Pods
    • Units of deployment
  • Replication Controller
    • Ensures availability and scalability
  • Labels
    • Key-Value pairs for identification
  • Services
    • Collection of pods exposed as an endpoint

Simple Deployment

Deployment->Service

kubectl run my-web –image=nginx –port=80

kubectl get deployments

devpc:~ apocoder$ kubectl run my-web –image=nginx –port=80
deployment.apps “my-web” created
devpc:~ apocoder$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
my-web 1 1 1 1 1m
devpc:~ apocoder$

devpc:~ apocoder$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-web-857d97b7cd-k754z 1/1 Running 0 2m

kubectl get svc

PORT=$(kubectl get svc my-web -o go-template='{{(index .spec.ports 0).nodePort}}’)

echo $PORT

30890

minikube ip

192.168.99.101

then visit the ->  http://192.168.99.101:30890

minikube dashboard

Perfect! You successfully deployed your nginx!

Kubernetes -02- Minikube

  • Install Oracle Virtualbox for Mac
  • Install Docker Toolbox for Mac
  • Install Docker Version Manager
  • Install kubectl
  • Install Minikube for Mac.

Launch minikube with the following command

minikube start –vm-driver=virtualbox

minikube status

kubectl get cs

 

minikube ssh

docker version

docker images

Success!

 

Ansible -2 – Configuration

Ansible configuration file at /etc/ansible/ansible.cfg

[defaults]

# some basic default values…

#inventory = /etc/ansible/hosts              ->   this is hosts are ansible using
#library = /usr/share/my_modules/      -> library
#module_utils = /usr/share/my_module_utils/
#remote_tmp = ~/.ansible/tmp
#local_tmp = ~/.ansible/tmp
#forks = 5
#poll_interval = 15
#sudo_user = root        -> sudo user
#ask_sudo_pass = True
#ask_pass = True
#transport = smart
#remote_port = 22
#module_lang = C
#module_set_locale = False