Skip to content

Instantly share code, notes, and snippets.

@matheusnascgomes
Forked from raisiqueira/README.MD
Created December 27, 2019 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheusnascgomes/a75dbd7d2f97a7dfbfdd5cd33348d94a to your computer and use it in GitHub Desktop.
Save matheusnascgomes/a75dbd7d2f97a7dfbfdd5cd33348d94a to your computer and use it in GitHub Desktop.
Install Docker

Install Docker

https://github.com/eon01/DockerCheatSheet

Install

curl -fsSL https://get.docker.com | sh;

docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Add permission to execute

sudo chmod +x /usr/local/bin/docker-compose

Add permission to the current user into docker group

sudo usermod -aG docker USERNAME

Install Kubernetes

turn off the swap memory to the cluster works fine!

swapoff -a

Deps

apt-get update && apt-get install -y apt-transport-https

Install K8s

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list && sudo apt-get update

apt-get install -y kubelet kubeadm kubectl

Starting the cluster

Downloading some components for k8s

run kubeadm config images pull

Create pod network (network police)

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

Run on master:

kubeadm init --apiserver-advertise-address $(hostname -i)

Run kubectl get nodes and see if the all nodes are ready.

Details for this podnetworks

kubectl get pods -n kube-system

Enable completions

https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion

Get ingress tokens (master and slave)

run kubeadm token create --print-join-command

Helm

https://github.com/helm/helm

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.14.0-linux-amd64.tar.gz

tar -zxvf helm-v2.0.0-linux-amd64.tgz

mv linux-amd64/helm /usr/local/bin/helm

or install via Snap

snap install helm --classic

Setup tiller to work on K8s namespace

kubectl create serviceaccount --namespace=kube-system tiller

Create a role binding for this service account

kubectl create clusterrolebinding tiller-cluster-role --clusterrole=cluster-admin --serviceaccount=kube-system:tiller

Path the tiller-deploy to add service account

kubectl patch deployments -n kube-system tiller-deploy -p '{"spec": {"template": {"spec": {"serviceAccount": "tiller"}}}}'

Minikube

For studies only, run on single machine.

Install Kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

add permission to run

chmod +x kubectl && mv kubectl /usr/local/bin/

curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v0.28.0/minikube-linux-amd64

Add permission to run

chmod +x minikube && mv minikube /usr/local/bin/

Docker Swarm

Init Swarm

docker swarm init --advertise-addr $(hostname -i)

Check nodes

docker node ls

Join to a cluster

docker swarm join-token manager|worker

Create a new service

docker service create --name nginx -p 80:80 nginx:stable-alpine

Example my image (https://github.com/raisiqueira/simple-py-docker)

docker service create --name rai --image raisiqueira/teste-version:1.0.0

Update Service

Example image (https://github.com/raisiqueira/simple-py-docker)

docker service update --image raisiqueira/teste-version:2.0.0

Check service

docker service ps NOMEDOSERVICO

Scale a service

docker service scale NOMEDOSERVICO=X

Inspect service

docker service inspect --pretty NOMEDOSERVICO

Misc

outras opcoes no service create (--update-parallelism, limit-memory, --limit-cpu, --update-parallelism) Dashboard grafana (https://grafana.com/dashboards/1505)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment