Kubernetes for Developers
Jeff French
DevOps and Cloud Migration Experts
@jeff_french
Principal Consultant
Kubernetes is a container orchestrator.
Other schedulers / orchestrators include:
Docker Swarm
Apache Mesos / DCOS
HashiCorp Nomad
a pod is a collection of containers and volumes
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /data
type: Directory
a service routes traffic to a set of pods
<service-name>.<namespace>.cluster.local
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- name: http
protocol: TCP
port: 80
targetPort: 9376
- name: https
protocol: TCP
port: 443
targetPort: 9377
An ingress exposes a service to the outside world
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/ingress.provider: nginx
kubernetes.io/tls-acme: "true"
nginx.ingress.kubernetes.io/proxy-body-size: 512m
nginx.ingress.kubernetes.io/proxy-connect-timeout: "15"
nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
name: gitlab-unicorn
namespace: gitlab
spec:
rules:
- host: gitlab.moonswitch.io
http:
paths:
- backend:
serviceName: gitlab-unicorn
servicePort: 8181
path: /
tls:
- hosts:
- gitlab.moonswitch.io
secretName: gitlab-gitlab-tls
Request Flow
a job runs a set of pods until successful completion
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
a deployment describes the desired state of a set of pods and manages updates to those pods
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
Max Unavailable
Absolute number or percentage of pods that can be unavailable at once during a deployment
Max Surge
Absolute number or percentage of pods that can be created in excess of the desired number of pods for a deployment
Rolling Update Strategies
maxUnavailable = 3
Our deployment may drop as low as 7 pods that are still active and serving traffic
maxSurge = 3
Our deployment may spike as high as 13 pods that are active and serving traffic
Rolling Update Strategies
Given a deployment with replicas = 10
a horizontal pod autoscaler scales out a deployment based observed CPU utilization or other metrics
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
Q & A Time!
Thanks!
Jeff French
Principal Consultant
Moonswitch
moonswitch.com
@jeff_french
Kubernetes for Developers
By Jeff French
Kubernetes for Developers
Kubernetes is a great way to get more density and scalability out of hardware or cloud platforms. As a developer, what do you need to know when writing apps that will run on Kubernetes? We’ll cover service discovery, secrets, scaling, runtime configuration and more.
- 1,303