- Senior Software Engineer at Mavenlink
- Bootcamp grad
- Koob noob
- Recent Kubecon attendee
- A little anxious
- Likes long walks on the beach
- Likes destroying toys
Receiving the Reddit "Hug of Death" blog post
- What is Kubernetes?
- Autoscaling in action
- How can I try it out?
Kubernetes is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation.
- Containerize our app with Docker
- Configure a Kubernetes cluster
- Write a deployment
- Write a service
- Write a horizontal pod autoscaler
- Deploy our app to the cluster!
require 'sinatra'
get '/' do
find_match_for_dog # some computationally expensive job
"Your dog's match was found by #{ENV['POD_NAME']}"
end
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it.
- Install packages
- Install languages, frameworks, and tools
- Install dependencies
- Install services (mySQL, Postgres, Redis, ElasticSearch, etc...)
# Specify a base image
# In this case, we want one that has Ruby preinstalled
FROM ruby:2.3.7
# Specify our working directory
WORKDIR /app
# Copy files from our current location on our local machine
# to the app directory in the Docker container
ADD . /app
# Install our dependencies
RUN cd /app && \
bundle install
# Expose a port
EXPOSE 4567
# Start our server when the Docker container is started
CMD ["ruby", "web.rb"]
A deployment declares your desired state of an application, usually as a series of pods and how they should be managed
A pod (as in a pod of whales or pea pod) is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers.
In laymans terms, pods are units of works or replicas of an application. And deployment describes how to configure them.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: dog-tinder
spec:
template:
metadata:
name: dog-tinder
labels:
service: dog-tinder
spec:
containers:
- name: dog-tinder-container
image: dog-tinder:latest
resources:
requests:
cpu: 200m
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
restartPolicy: Always
# How much resources should we allocate to this pod?
resources:
requests:
cpu: 200m
1/5th of a CPU core
A service allows other things to access your deployment. In our case we want to view our app from a browser!
In other case you might need to configure a service so that your app could connect to a database
apiVersion: v1
kind: Service
metadata:
labels:
service: dog-tinder
name: dog-tinder-service
spec:
type: NodePort
ports:
- name: dog-tinder-port
port: 4000
protocol: TCP
targetPort: 4567
nodePort: 30000
selector:
service: dog-tinder
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: dog-tinder-hpa
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
name: dog-tinder
targetCPUUtilizationPercentage: 50
targetCPUUtilizationPercentage: 50
50% * 200m = 100m
- Tutorials - Kubernetes
- Getting started with Kubernetes as an Application Developer
- The Childrens Illustrated Guide to Kubernetes
Check it out, file an issue if its confusing and I'll update it!