Introduction to Kubernetes
What you can expect
from this presentation
- Understanding basic concepts of Container
- Understanding basic concepts of Kubernetes
- Seeing Kubernetes live in action
What you shouldn't expect from this presentation
- Advanced concepts of Container
- Advanced concepts of Kubernetes
- Thorough guides on how to manage Kubernetes cluster
The Driving-a-Car Philosophy
It’s like learning to drive a car. In the beginning, you don’t really want to know what’s under the hood. You first want to learn how to drive it from point A to point B. Only after you learn how to do that do you become interested in how a car makes that possible. After all, knowing what’s under the hood may someday help you get the car moving again after it breaks down and leaves you stranded at the side of the road.

A Little Bit History
To grasp some context.


BC = Before Container


The Monolith
Monolithic vs Microservice (1)
- Tightly coupled
- Have to be developed, deployed, and managed as one entity
- Run as single OS processes
- Highly decoupled
- Each component can be developed, deployed, and managed independently
- Each component runs as independent process
Monolithic vs Microservice (2)

Microservice is Highly Scalable

But, as Uncle Ben Said
With great numbers of components comes great responsibility, Peter...

Dependencies Madness...

Virtual Machine
Before containers went mainstream, we isolate components using Virtual Machine (VM). This way, each components can have their own dependencies satisfied without getting in the way of each other.
The problem with VM is that it takes a lot of hardware resources, therefore not ideal for microservice-based app with large number of services.
Docker to The Rescue!
How Docker made containers mainstream.
VM vs Container (1)
- Runs on own OS
- Runs its own system processes
- Runs on host OS
- Runs as isolated processes in host OS
VM vs Container (2)

VM vs Container (3)


But How is That Possible?
- Linux Namespaces
- Linux Control Groups
But Why Docker?
Docker was the first container system that made containers easily portable across different machines. It simplified the process of packaging up not only the application but also all its libraries and other dependencies, even the whole OS file system, into a simple, portable package that can be used to provision the application to any other machine running Docker.
Docker Components

Docker Hello World
Run:
docker run busybox echo "Hello World"Result:


What Just Happened?
Something Less Trivial (1)
A simple NodeJs app:
const http = require('http');
const os = require('os');
console.log("Kubia server starting...");
var handler = function(request, response) {
console.log("Received request from " + request.connection.remoteAddress);
response.writeHead(200);
response.end("You've hit " + os.hostname() + "\n");
};
var www = http.createServer(handler);
www.listen(8080);Something Less Trivial (2)
A simple Dockerfile:
FROM node:7
ADD app.js /app.js
ENTRYPOINT ["node", "app.js"]Build it:
docker build -t kubia .
Something Less Trivial (3)
Check for all the images:
docker imagesRun the container image:
docker run --name kubia-container -p 8080:8080 -d kubiadocker psCheck for all the running containers:
What Happened Just Now?

Take a Look Inside
Inspect the container:
docker inspect kubia-containerGet inside the container:
docker exec -it kubia-container bash
ps auxps aux | grep app.jsOutside of the container:
Push Image to Registry
Login to Docker Hub (if you haven't already):
docker loginTag the image and push it:
docker tag kubia qblfrb/kubia
docker push qblfrb/kubiaKubernetes
is Greek for:
- pilot
- helmsman
- governor
Where Kubernetes Fits In
Kubernetes is a software system that allows you to easily deploy and manage containerized applications on top of it.
Kubernetes enables you to run your software applications on thousands of computer nodes as if all those nodes were a single, enormous computer.
Kubernetes can be thought of as an operating system for the cluster.
High Level Abstraction

Kubernetes Components

Kubernetes + Docker

Kubernetes Hello World
Before we continue, we need to have either a cloud cluster set up or a minikube installed. For this presentation we'll create a cluster in Google Cloud Platform. Here are the steps:
- Create a GCP account (we'll get $300 free credit!)
- Have API enabled for Kubernetes Engine
Preparation
Create the cluster:
gcloud container clusters create kubia --num-nodes 3 --machine-type f1-microVerifying everything is ready:
kubectl config get-contexts
kubectl get nodes
kubectl describe node gke-kubia-default-pool-84262666-7rsl
What Happened Just Now?
Deploy The App
Use `kubectl run` command:
kubectl run kubia --image=qblfrb/kubia --port=8080 --generator=run/v1See the results:
kubectl get podsWhat Happened Just Now?

Expose The App
Get the replication controller:
kubectl get replicationcontrollerExpose it:
kubectl expose rc kubia --type=LoadBalancer --name kubia-httpGet the service:
kubectl get servicesTest it:
curl 35.185.155.217:8080The Logical Part

Pod
A pod is a co-located group of containers and represents the basic building block in Kubernetes. The key thing about pods is that when a pod does contain multiple containers, all of them are always run on a single worker node—it never spans multiple worker nodes.
Replica Controller
A ReplicationController is a Kubernetes resource that ensures its pods are always kept running. If the pod disappears for any reason, such as in the event of a node disappearing from the cluster or because the pod was evicted from the node, the ReplicationController notices the missing pod and creates a replacement pod.
Service
A Kubernetes Service is a resource you create to make a single, constant point of entry to a group of pods providing the same service. Each service has an IP address and port that never change while the service exists. Clients can open connections to that IP and port, and those connections are then routed to one of the pods backing that service. This way, clients of a service don’t need to know the location of individual pods providing the service, allowing those pods to be moved around the cluster at any time.
What's Next?
A Lot More to Learn!
Recommended Reading
- Kubernetes in Action
- Kubernetes by Example
Introduction to Kubernetes
By qblfrb
Introduction to Kubernetes
- 489