Created by Laurence J MacGuire a.k.a. Laz a.k.a. 刘建明
ThoughtWorks Bangkok, 2017/02/05
Hi to Phisit!
Docker. Docker. Docker
Not all that much. It all existed before.
What is that thing?
Provides and builds upon simple primitives
Runs on bare-metal or VMs
It’s a swagger API!
Reliable key-value store for the most critical data of a distributed system
Composing coherent primitives.
All these things live in a namespace
One logical process.
$ kubectl create -f ./manifests/v1/pod.yml
pod "nginx-static-app-on-k8s" created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-static-app-on-k8s 1/1 Running 1 1d
$ kubectl logs nginx-static-app-on-k8s
172.17.0.1 - - [04/Feb/2017:09:47:36 +0000] "GET / HTTP/1.1" 200 287 "-" "Go-http-client/1.1" "-"
172.17.0.1 - - [04/Feb/2017:09:47:38 +0000] "GET / HTTP/1.1" 200 287 "-" "Go-http-client/1.1" "-"
172.17.0.1 - - [04/Feb/2017:09:47:41 +0000] "GET / HTTP/1.1" 200 287 "-" "Go-http-client/1.1" "-"
A Pod/Process that is meant to finish
$ kubectl create -f manifests/job/job.yml
job "who-am-i" created
kubectl get jobs
NAME DESIRED SUCCESSFUL AGE
who-am-i 10 10 2m
A Job that is meant to finish and restart periodically.
apiVersion: batch/v2alpha1
kind: ScheduledJob
metadata:
name: example-cron-job
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: my-cron-job
image: busybox:1.25.0
args:
- whoami
restartPolicy: OnFailure
$ kubectl create -f ./cronjob.yaml
cronjob "example-cron-job" created
$ kubectl get scheduledjob
NAME SCHEDULE SUSPEND ACTIVE LAST-SCHEDULE
example-cron-job */1 * * * * False 0 Sun, 05 Feb 2017 11:52:00 +0700
$ kubectl get jobs
NAME DESIRED SUCCESSFUL AGE
example-cron-job-1706329924 1 1 2m
example-cron-job-1782286151 1 1 51s
example-cron-job-1858111306 1 1 1m
example-cron-job-2010351440 1 1 3m
example-job 1 1 11m
Define groups of pods w/ count, affinity & lifecycle
A Pod scheduled to run with N replicas
Hint! Hint! This smells like horizontal scaling!
A Pod scheduled to run on ALL nodes of a cluster.
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube2iam
labels:
app: kube2iam
spec:
template:
metadata:
labels:
name: kube2iam
spec:
hostNetwork: true
containers:
- image: jtblin/kube2iam
name: kube2iam
A ReplicaSet, but …
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
Wraps a ReplicaSet and exposes less RESTy API actions.
Eg, “rollout”
No one can access our app. Not really anyway.
We’ve got a bunch of IP:Port combinations our app responds on. What do we need now?
AKA, “a service”
$SERVICE_NAME.$NAMESPACE.svc.cluster.local
nginx-static-app-on-k8s.default.svc.cluster.local
We get a stable name, and a stable ip. YAY!
Public HTTP entrypoint to a service
12 Factor App: Store config in the environment
ConfigMaps & Secrets
apiVersion: v1
kind: ConfigMap
metadata:
name: game-config
data:
config.yaml: |
---
config:
db:
host: db.blah.com
Can then be injected in a Pods ENV vars, or as a file in a volume.
The exact same thing.
But with upcoming additional contraints.
Notable Differences