Share
Embed
Docker and Kubernetes
Towards micro-services architectures with Docker and Kubernetes
Roberto Zen
March 14, 2017
Transcript
30 slides
-
Dockerfile - Used by docker build - INSTRUCTION arguments -
The first instruction must be `FROM` - FROM, RUN, CMD, COPY, ADD, - LABEL, ENV, WORKDIR, EXPOSE, … See https://github.com/docker-library/rails https://docs.docker.com/engine/reference/builder/ -
https://hub.docker.com You don’t have to reinvent the wheel (public vs
private) 460K images -
What if I want to run multiple containers? Use docker-compose!
You just need a docker-compose.yml -
https://kubernetes.io Kubernetes (k8s) is an open-source system for automating deployment,
scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon 15 years of experience of running production workloads at Google, combined with best-of-breed ideas and practices from the community. What is Kubernetes? -
https://kubernetes.io Automatic binpacking Self-healing Horizontal scaling Service discovery and load
balancing Automated rollouts and rollbacks Kubernetes Features -
Kubernetes Master API UI CLI ETCD API SERVER SCHEDULER CONTROLLER
The master is responsible for exposing the application program interface (API), scheduling the deployments and managing the overall cluster. -
Kubernetes Master API UI CLI ETCD API SERVER SCHEDULER CONTROLLER
The API server validates and configures data for the api objects which include pods, services, replication controllers, and others. The API Server services REST operations and provides the frontend to the cluster’s shared state through which all other components interact. -
Kubernetes Master API UI CLI ETCD API SERVER SCHEDULER CONTROLLER
The scheduler is a workload- specific function that significantly impacts availability, performance, and capacity. The scheduler needs to take into account individual and collective resource requirements, quality of service requirements, … -
Kubernetes Master API UI CLI ETCD API SERVER SCHEDULER CONTROLLER
The controller a controller is a control loop that watches the shared state of the cluster through the api server and makes changes attempting to move the current state towards the desired state. -
Kubernetes Master API UI CLI ETCD API SERVER SCHEDULER CONTROLLER
ETCD is a highly-available key value store which Kubernetes uses for persistent storage of all of its REST API objects. -
https://kubernetes.io/docs/resources-reference/v1.5/#container-v1 Container name: nginx # Run the nginx:1.7.9 image image:
nginx:1.7.9 ports: - name: http containerPort: 8080 env: - name MY_ENV_VARIALBE value: my-value A simple container.* *Containers are only ever created within the context of a Pod. This is usually done using a Controller. See Controllers: Deployment, Job, or StatefulSet. or -
https://kubernetes.io/docs/user-guide/pods/ Pod A Pod is a group of one or
more containers that share the same hostname. Pod templates are pod specifications which are included in other objects, such as Replication Controllers, Jobs, and DaemonSets. Controllers use Pod Templates to make actual pods. -
Labels and Selectors Labels are key/value pairs associated with kubernetes
objects. They are used to query subsets of objects. Essential glue to associate one API object with other: - ReplicationController - Pods - Services - Pods - Pods - Nodes https://kubernetes.io/docs/user-guide/labels/ apiVersion: v1 kind: Pod metadata: name: nginx labels: type: frontend -
https://kubernetes.io/docs/user-guide/replication-controller/ Replication Controller A ReplicationController ensures that a specified number
of pod “replicas” are running at any one time. If there are too few, the ReplicationController will start more. Unlike manually created pods, the pods maintained by a ReplicationController are automatically replaced if they fail, get deleted, or are terminated. apiVersion: v1 kind: ReplicationController metadata: name: nginx spec: replicas: 3 selector: app: nginx template: metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 -
https://kubernetes.io/docs/user-guide/deployments/ Deployment A Deployment provides declarative updates for Pods and
Replica Sets (the next- generation Replication Controller). You only need to describe the desired state in a Deployment object, and the Deployment controller will change the actual state to the desired state at a controlled rate for you. apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 -
https://kubernetes.io/docs/user-guide/pods/ Pod, what’s the problem? Kubernetes Pods are mortal. They
are born and when they die, they are not resurrected. While each pod gets its own IP address, even those IP addresses cannot be relied upon to be stable over time. -
https://kubernetes.io/docs/user-guide/services/ Service A single pod or a replica set can
be exposed to the internal or external consumers via Services. apiVersion: v1 kind: Service metadata: name: my-service spec: selector: name: nginx type: NodePort ports: - port: 8080 name: http -
https://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/walkthrough/ Horizontal Pod Autoscaler Horizontal Pod Autoscaling (HPA) automatically scales
the number of pods in a replication controller, deployment or replica set based on observed CPU utilization. -
https://github.com/kubernetes/minikube Minikube Minikube is a tool that makes it easy
to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day. -
References • Getting started with docker, the step by step
tutorial with examples https://www.youtube.com/watch?v=Vyp5_F42NGs • Docker Containers and Kubernetes with Brian Dorsey https://www.youtube.com/watch?v=Fcb4aoSAZ98