kubernetes20151017a

22
Kubernetes a study note

Upload: richard-kuo

Post on 22-Jan-2018

353 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Kubernetes20151017a

Kubernetes

a study note

Page 2: Kubernetes20151017a

Outline

• Container– Docker, Rocket, LXC/LXD, …

• Cluster– CoreOS

• Cluster Management– Kubernetes, ...

• Demo– Vagrant, Google Cloud

2

rocket

20151021 cc by-nc 3.0

Page 3: Kubernetes20151017a

Container

• An isolated Linux execution environment.

• leverages OS virtualization.

• runs in different OS, cloud providers.

320151021 cc by-nc 3.0

Page 4: Kubernetes20151017a

CoreOS

• Light weight OS based on Linux

• Distributed storage

• Auto-update

420151021 cc by-nc 3.0

Page 5: Kubernetes20151017a

CoreOS

20151021 cc by-nc 3.0 5

Page 6: Kubernetes20151017a

etcd

write:$ etcdctl set /message Hello

or

$ curl -L -X PUT http://127.0.0.1:4001/v2/keys/message -d value="Hello"

read: $ etcdctl get /message

or

$ curl -L http://127.0.0.1:4001/v2/keys/message

20151021 cc by-nc 3.0 6

Page 7: Kubernetes20151017a

fleet

Manage nodes, pods, services via fleetctl

COMMANDS:

cat Output the contents of a submitted unit

destroy Destroy one or more units in the cluster

fd-forward Proxy stdin and stdout to a unix domain socket

help Show a list of commands or help for one command

journal Print the journal of a unit in the cluster to stdout

list-machines Enumerate the current hosts in the cluster

list-unit-files List the units that exist in the cluster.

list-units List the current state of units in the cluster

load Schedule one or more units in the cluster, first submitting them if necessary.

ssh Open interactive shell on a machine in the cluster

start Instruct systemd to start one or more units in the cluster, first submitting and loading if necessary.

status Output the status of one or more units in the cluster

stop Instruct systemd to stop one or more units in the cluster.

submit Upload one or more units to the cluster without starting them

unload Unschedule one or more units in the cluster.

verify DEPRECATED - No longer works

version Print the version and exit

20151021 cc by-nc 3.0 7

Page 8: Kubernetes20151017a

820151021 cc by-nc 3.0

Page 9: Kubernetes20151017a

Why?

Challenges:• Commodity hardware not reliable• App execution environment moves around• Different developing and deployment software stacks, and many best

practices• Varies events occur at wide geographic area that effects our context, the

information are different type, changes very fast, large amount

Containers, Cluster OS and management system can help us to deal with the problems.

920151021 cc by-nc 3.0

Page 10: Kubernetes20151017a

1020151021 cc by-nc 3.0

Page 11: Kubernetes20151017a

Kubernetes

• Is a platform for hosting containers in a clustered environment with multiple hosts

• Provides container grouping, load balancing, auto scaling, and self-healing

• Started by Google,

[google white paper]:http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43438.pdf

20151021 cc by-nc 3.0 11

Page 12: Kubernetes20151017a

1220151021 cc by-nc 3.0

http://blog.arungupta.me/wp-content/uploads/2015/01/kubernetes-architecture.png

Kubernetes Architecture

Page 13: Kubernetes20151017a

1320151021 cc by-nc 3.0

Page 14: Kubernetes20151017a

Main Components

Master• maintains state of kubernetes server

with etcd.• is the entry point of Kubernetes

client to configure and manage Nodes, Pods, Replicators, Services.

• reconcile the difference between the current state and desired state.

Worker Node• run a command from master node• report current node state

20151021 cc by-nc 3.0 14

Page 15: Kubernetes20151017a

Master

Replication Controller

• Uses Pod Templates to create Pods

• Uses Label to monitor and maintain the desired Pods level at any one time

Service Registry

• Is a wrapper on top of etcd persistent storage, which keep track of services

• can be performed on registry: create service, update, delete, ...

API Server

• Scheduler

• AuthenticationDistributed Watchable Storage

• States of Kubernetes

• Configuration

• Watch changes

20151021 cc by-nc 3.0 15

Page 16: Kubernetes20151017a

Work Node

Service

• An abstraction layer defined a logic set of Pods and access policy to deliver the functions.

• Selector gets a set of Pods per their Labels.

• Elements of service: Name, Port of Proxy, Selector, Uses load balance

Pod

• Label

• Share Volume

• visible IP

• single or multiple containers

• template

20151021 cc by-nc 3.0 16

Page 17: Kubernetes20151017a

Kubectl

• run on each node, manage life cycle of Pods

• 1:1 map to host

• communicate among themselves to keep information up to date, data is stored in a distributed, watchable storage

• main elements:

– cAdviser: monitor and display Pods status

– etcd client: interface with central storage

– docker client: for create, start, stop, delete container

Functions:

• run a action on a Pod

• bind a Volume to container

• bind ports to containers

• provide container health information

• interface with host

20151021 cc by-nc 3.0 17

Page 18: Kubernetes20151017a

Demo

1820151021 cc by-nc 3.0

Page 19: Kubernetes20151017a

Kubernetes on gcloud

## create a cluster ➜ gcloud container clusters create guestbook

## create redis master controller ➜ kubectl create -f redis-master-controller.json`

## get pods info ➜ kubectl get pods -l name=redis-master

## login container ➜ gcloud compute ssh gke-guestbook-7dc33b44-node-9tlv

## get available docker images rkuo@gke-guestbook-7dc33b44-node-9tlv:~$ sudo docker images

## create redis master service ➜ kubectl create -f redis-master-service.json`

## create the guestbook web server pods

## create frontend controller ➜ kubectl create -f frontend-controller.json

## start frontend web service: ➜ kubectl get services

20151021 cc by-nc 3.0 19

Page 20: Kubernetes20151017a

Thank You!

richard kuo

2020151021 cc by-nc 3.0

Page 21: Kubernetes20151017a

2120151021 cc by-nc 3.0

Page 22: Kubernetes20151017a

20151021 cc by-nc 3.0 22