This is to hold the slides and all demo material for the meetup / workshop
- git [source control system]
- Docker Desktop [container management tool]
Download the Docker Desktop application and install, if on Windows 10 switch to Linux context by clicking the Switch to Linux option from the whale in the tray.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.
Navigate to the folder: 15.06.2019.Kubernetes.Workshop/demo/dockerfile
A documented specification what how to create your application so that it can be executed.
Example:
FROM node:11 AS build
LABEL CLI-VERSION="6.0.0"
RUN useradd --user-group --create-home --shell /bin/false app
ENV HOME=/home/app
WORKDIR $HOME
RUN npm install -g @angular/[email protected] \
&& npm install @angular/[email protected] --save \
&& npm install yarn
COPY awesome-sauce .
RUN yarn install
RUN ng build
FROM nginx
ADD default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /home/app/dist/awesome-sauce /usr/share/nginx/html
EXPOSE 80
A compiled specification of your software stored in a repository.
docker build .
Example: Docker will get the missing images
Example
After the build you can see the images created by running:
docker images
Example: docker images untagged
Name the image by tagging the image:
docker build -t awesome-sauce:1 .
docker run -d -p 81:80 --rm awesome-sauce:1
Break down this command:
[docker runtime] [action] -[option: detached] -[option: bind ports] -[option: remove if existed] [image: required image]
Open the browser and go to http://localhost:81:
A quick way to get a list of the running containers is by running:
docker ps
To stop the container, use the name for the container from the docker ps command and run the docker kill .
docker kill brave_austin
To push images you need to login to the image repository, after creating an account on Docker Hub, simply run:
docker login -u <username> -p <password>
Example:
Share your image with others as sharing is caring. After creating the repository on docker Hub, lets re-tag the image as per the Docker hub repository by running:
docker tag <image-hash> <new-name>
Example:
docker tag 38cb7753b9e8 dockerdurban/awesome-sauce
Now that we have a image tagged in our accounts namespace we can simply push the image:
docker push dockerdurban/awesome-sauce:1
Example:
To see the pushed image open a browser and go to: dockerdurban/awesome-sauce.
Docker comes with a tool to orchestrate your applications in a simple manner with a .yml file definition.
Navigate to the folder: 15.06.2019.Kubernetes.Workshop/demo/docker-compose
Example:
version: '3'
services:
web:
image: awesome-sauce:1
ports:
- '8090:80'
cache:
image: redis:alpine
In this folder we have the docker-compose.yml which has the stack specification that is required for a deployment.
- website that we created
- some backend service, in this example a redis server
To run the deployment you can use the command docker-compose up
in the directory that you have the file.
docker-compose up
Example
Open the browser to the port in the docker-compose.yml file i.e. 8090
To bring the deployment down simple cancel the terminal and the engine will gracefully kill the containers.
To run the deployment as a service run:
docker-compose up -d
example
To see what deployments are running run the command:
docker-compose ps
Example:
That will detach the terminal and the deployment will run. To remove the deployment run the command:
docker-compose down
Example:
For more information check out Docker-Compose Deploy Stack
Kubernetes is an open-source container-orchestration system for automating application deployment, scaling, and management.
It was originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.
Navigate to the folder: 15.06.2019.Kubernetes.Workshop/demo/kubernetes
Click on the Docker desktop application, then click preferences / settings select Kubernetes and check enable Kubernetes.
kubectl controls the Kubernetes cluster manager.
kubectl get nodes
Docker comes with swarm as the default orchestrator, you can set the orchestrator for all deployments or set it when deploying the stack.
- set DOCKER_STACK_ORCHESTRATOR=swarm
- set DOCKER_STACK_ORCHESTRATOR=kubernetes
Set the orchestrator when deploying:
docker stack deploy --orchestrator kubernetes --compose-file demo-one-deploy.yml demo-one-stack
kubectl get pods
docker stack rm demo-one-stack
- kubectl apply : Manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster.
Examples
kubectl apply -f ./my-manifest.yaml # create resource(s)
kubectl apply -f ./my1.yaml -f ./my2.yaml # create from multiple files
kubectl apply -f ./dir # create resource(s) in all manifest files in dir
kubectl apply -f https://git.io/vPieo # create resource(s) from url
kubectl create deployment nginx --image=nginx # start a single instance of nginx
kubectl explain pods,svc # get the documentation for pod and svc manifests
- kubectl get services: List all services in the namespace
- kubectl get pods --all-namespaces: List all pods in all namespaces
- kubectl get deployment my-dep: List a particular deployment
- kubectl describe pods my-pod: Describe commands with verbose output
For more check out kubectl Cheat Sheet
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
Now set the proxy so that you can navigate to the dashboard
kubectl proxy
Copy and paste into a browser:
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
$TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1]
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"
- Click on Kubeconfig and select the “config” file under /users/.kube\config
Once logged in you will see the dashboard.
To Stop the dashboard simply exit the proxy command from earlier.
A unit of work, contains one or more containers
A worker machine in Kubernetes, part of a cluster.
A set of Nodes that run containerized applications managed by Kubernetes. For this example, and in most common Kubernetes deployments, nodes in the cluster are not part of the public internet.
A Kubernetes Service that identifies a set of Pods using label selectors. Unless mentioned otherwise, Services are assumed to have virtual IPs only routable within the cluster network.
kubectl apply -f awesome-sauce-deploy.yaml