Вы находитесь на странице: 1из 10

Docker/Kubernetes Readme

Various links to website has been added. Check them out for more detailed info.

Use this link for a quick start (Best guide) -


https://medium.freecodecamp.org/learn-kubernetes-in-under-3-hours-a-detailed-
uide-to-orchestrating-containers-114ff420e882

To get a quick handson with kubernetes online -


https://www.katacoda.com/courses/kubernetes

Steps to learn for complete beginners-

1. Understand microservices architecture - https://smartbear.com/learn/api-


design/what-are-microservices/
2. Try breaking the required web app into microservices
3. Understand need of docker
4. Learn Docker
5. Install and setup docker on system-
https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce-1
6. Make Dockerfile for each microservices to build docker images of each
microservices separately
7. Run docker containers and test functionality for each microservice
8. Understand need of kubernetes
9. Learn kubernetes
10. Install minikube/kubeadm and kubectl on system
11. Make .yml files for each deployment, service, volume etc
12. Test individual functionalities
13. Test whole webapp
14. Test features like zero downtime deployment, rolling update and rollout,
scaling, persistent volume storage, load balancing etc.

Docker Readme
===================Getting Started Docker============================

1. Installing Docker on Ubuntu : https://docs.docker.com/install/linux/docker-


ce/ubuntu/#install-docker-ce-1
2. Building Docker Image :
https://docs.docker.com/engine/reference/commandline/build/
3. Running Docker Images : https://docs.docker.com/engine/reference/run/

===========Steps to build and run docker images====================

1. Make Dockerfile
2. Build image using Dockerfile also use a tag
3. Run container using the image we have built
4. Test container
5. Push Image to docker registry

** Use docker run with -i option to run terminal inside docker container

===========================Docker Commands===========================

To build their own Docker images:


$ docker build -t ImageName:TagName dir

Displaying Docker Images:


$ docker images
To see the details of the container:
$ docker inspect Repository

Running a Container:
To run a container in an interactive mode:
$ sudo docker run –it centos /bin/bash

see all the commands that were run with an image via a container:
$ docker history ImageID

See the top processes within a container:


$ docker top ContainerID

To provide the statistics of a running container:


$ docker stats ContainerID

To stop a running container:


$ docker stop ContainerID

This method allows one to tag an image to the relevant repository:


$ docker tag imageID Repositoryname

to push images to the Docker Hub:


$ docker push Repositoryname

to delete a container:
$ docker rm ContainerID

Removing Docker Images:


$ docker rmi ImageID
to set environment variables in the container:
$ ENV key value

##Docker Compose
Docker Compose is used to run multiple containers as a single service.

run our Docker Compose file using the following command:


$ sudo ./docker-compose up
$ docker-compose up

===================Update Docker Image =================================

1. Build first docker image with a tag


2. Build new image with same name and a different tag
3. Tag :latest tag image with new tag
4. Similarly just assign image with latest tag to desired old and new image

=======================References for Docker============================

1. https://hub.docker.com/_/ubuntu/

2. https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

3. https://docs.docker.com/engine/reference/builder/

4. https://docs.docker.com/get-started/

5. https://www.tutorialspoint.com/docker/index.htm

---------------------------------------------------------------------------------------------------------------------------------------------
Kubernetes Readme
===================Getting started kubernetes============================

Installing Kubernetes tools minikube and kubectl -


https://kubernetes.io/docs/tasks/tools/install-minikube/,
https://kubernetes.io/docs/tasks/tools/install-kubectl/

Kubernetes Basics - https://kubernetes.io/docs/tutorials/kubernetes-basics/

============================Kubernetes Commands=====================
Starting node:
$ minikube start

In order to pull the image and create a container, we will run the following command:
$ kubectl create –f Tesing_for_Image_pull

To run Single Container Pod :


$ kubectl run tomcat --image = tomcat:8.0

Controls:
$ kubectl create –f pod.yml #Making Pods
$ kubectl get pods #Show running pods
$ kubectl get pod <Pod name>
$ kubectl describe pod <Pod name> ---->4
$ kubectl delete pod <Pod name>

**Similar commands for Services, Replication Controllers, Deployments etc

To monitor minikube cluster:


$ minikube dashboard

To stop local node -


$ minikube stop

Types of .yaml files (each to control specific features):


Services
Load Balancer
Replication Controllers
Deployments
Secrets
Namespace

============================Kubernetes References=======================

1. https://medium.freecodecamp.org/learn-kubernetes-in-under-3-hours-a-detailed-
uide-to-orchestrating-containers-114ff420e882 (Best)
2. https://www.tutorialspoint.com/kubernetes/index.htm

3. https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-
service-proxies

4. https://kukulinski.com/10-most-common-reasons-kubernetes-deployments-fail-part-
1/

5. https://deis.com/blog/2016/kubernetes-illustrated-guide/

6. https://kubernetes.io/docs/concepts/services-networking/service/

7. https://kubernetes.io/docs/concepts/storage/volumes/

==============================Services=============================
A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy
by which to access them - sometimes called a micro-service. The set of Pods targeted
by a Service is (usually) determined by a label selector.

$ kubectl apply -f service-sa-logic.yaml

==============================Volumes=============================

In Kubernetes, a volume can be thought of as a directory which is accessible to the


containers in a pod.

*It is better to use kubernetes volumes instead docker volume.

Persistent Volume (PV) − It’s a piece of network storage that has


been provisioned by the administrator. It’s a resource in the cluster
which is independent of any individual pod that uses the PV.

Command to get mounted persistent volumes


$ kubectl get pv

Add volumeMount spec in pod.yml to mount volume to all the pods.

================Steps to run using local image=================

** Docker + Kubernetes

1. Start minikube cluster


2. Use environment variable => eval $(minikube docker-env)
3. Change directory to exicom_trap_handler folder
4. Build Image (Make dockerfile first)
5. Test run
6. Stop running image
7. Create pod from exicom_trap_handler-pod.yml
8. Create Services from yml files
9. Mount volumes if needed
10. Test
11. Delete Pod
12. Create Deployment from exicom_trap_handler-deployment.yml

==========================Steps to run using online registry===============

** Docker + Kubernetes

1. Start minikube cluster


2. Change directory to exicom_trap_handler folder
3. Build Image with a tag (Make dockerfile first)
4. Push image to online registry
5. Tag latest image
6. Create pod from exicom_trap_handler-pod.yml
7. Create Services from yml files
8. Create Deployment from exicom_trap_handler-deployment.yml
9. Maintain

Note -
Change image pull back policy accordingly

============================Scale up or down===========================

$ kubectl autoscale deployment <Application Name> --cpu-percent = 50 --min = 1 --


max = 10

Or change number of replicas in yml file

===============================Rolling Update========================
We can have a zero downtime rolling update with kubernetes.
$ kubectl apply -f deploy-frontend-green-pods.yaml --record

$ kubectl rollout status deployment sa-frontend

===================================Roll Back=========================

$ kubectl rollout history deployment sa-frontend

$ kubectl rollout undo deployment sa-frontend --to-revision=1

==================Some Useful links for mysql with kubernetes================

1. https://stackoverflow.com/questions/47729304/create-kubernetes-pod-with-
mysql-and-php
2. https://stackoverflow.com/questions/29679661/connecting-tomcat-webapp-
running-in-docker-container-to-mysql
3. https://linoxide.com/containers/setup-mysql-kubernetes/
4. https://hub.docker.com/_/mysql/

======================Running Stateful Services===========================

https://www.katacoda.com/courses/kubernetes/storage-introduction

https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-
application/#simulating-pod-and-node-downtime

======================Multi Node Cluster with kubeadm==============

https://www.katacoda.com/courses/kubernetes/getting-started-with-kubeadm

https://kubernetes.io/docs/setup/independent/high-availability/#installing-
prerequisites-on-masters

https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
======================Managing Secrets and passwords==============
https://www.katacoda.com/courses/kubernetes/managing-secrets

======================Choosing deployment type================


https://kubernetes.io/docs/setup/pick-right-solution/

=====================Kubeadm==================================

Kubeadm is multi node kubernetes cluster making tool. Using this tool we can make
master-worker architecture clusters.

Installing- https://kubernetes.io/docs/tasks/tools/install-kubeadm/
Guide - https://www.mirantis.com/blog/how-install-kubernetes-kubeadm/
Trying online - https://www.katacoda.com/courses/kubernetes/getting-started-with-
kubeadm
Using guide - https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

--------------------------------------------------------------------------------------------------------------------------------------------

Вам также может понравиться