[Descomplicando o Kubernetes ] 02 - INSTALANDO e CONFIGURANDO um CLUSTER KUBERNETES

Atualizado: Mar 12




SIGA O VÍDEO


INSTALANDO O DOCKER


Bora realizar a instalação do Docker


# curl -fsSL https://get.docker.com | bash


Assim, teremos a última versão do docker instalado em todos os nodes.


INSTALANDO O KUBERNETES


Agora vamos adicionar o repo do Kubernetes em nossos nodes:


Debian e Familia:

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


# 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


# apt-get update


# apt-get install -y kubelet kubeadm kubectl


======================================

Red Hat e Familia


# vim /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes

baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64

enabled=1

gpgcheck=1

repo_gpgcheck=1

gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg


# setenforce 0


# systemctl stop firewalld


# systemctl disable firewalld


# yum install -y kubelet kubeadm kubectl


# systemctl enable kubelet && systemctl start kubelet


Ainda na família do Red Hat, é importante configurar alguns parâmetros de kernel no sysctl:


# vim /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1


# sysctl --system


Agora em ambas as distribuições é muito importante também verificar se o drive cgroup usado pelo kubelet é o mesmo usado pelo docker, para verificar isso execute o seguinte comando:


# docker info | grep -i cgroup

Cgroup Driver: cgroupfs


# sed -i "s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf


# systemctl daemon-reload


# systemctl restart kubelet


docs: https://kubernetes.io/docs/setup/independent/install-kubeadm/

===================================================


Antes de iniciar o nosso cluster precisamos desabilitar nossa swap, portanto:

# swapoff -a


E comente a entrada referente a swap em seu arquivo fstab:

# vim /etc/fstab



Agora vamos iniciar o nosso cluster


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


O comando acima irá iniciar o cluster e em seguida exibirá a linha que de comando que preciso executar em meus outros nodes.


[WARNING SystemVerification]: docker version is greater than the most recently validated version. Docker version: 18.05.0-ce. Max validated version: 17.03

...

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

...

kubeadm join --token 39c341.a3bc3c4dd49758d5 IP_DO_MASTER:6443 --discovery-token-ca-cert-hash sha256:37092

...


# mkdir -p $HOME/.kube


# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config


# sudo chown $(id -u):$(id -g) $HOME/.kube/config


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

serviceaccount/weave-net created

clusterrole.rbac.authorization.k8s.io/weave-net created

clusterrolebinding.rbac.authorization.k8s.io/weave-net created

role.rbac.authorization.k8s.io/weave-net created

rolebinding.rbac.authorization.k8s.io/weave-net created

daemonset.extensions/weave-net created


Vamos listar esses podnetwork:


# kubectl get pods -n kube-system

NAME READY STATUS RESTARTS AGE

coredns-78fcdf6894-fzbp2 1/1 Running 0 9m

coredns-78fcdf6894-vp6td 1/1 Running 0 9m

etcd 1/1 Running 0 7m

kube-apiserver 1/1 Running 0 8m

kube-controller-manager 1/1 Running 0 8m

kube-proxy-smhxn 1/1 Running 0 9m

kube-scheduler- 1/1 Running 0 8m

weave-net-9b6kg 2/2 Running 0 2m


# kubeadm join --token 39c341.a3bc3c4dd49758d5 IP_DO_MASTER:6443 --discovery-token-ca-cert-hash sha256:37092


Para verificar todos os nodes do cluster execute:


# kubectl get nodes

NAME STATUS ROLES AGE VERSION

linuxtips-centos Ready <none> 14s v1.11.0

linuxtips-debian Ready master 14m v1.11.0

linuxtips-debian2 Ready master 13m v1.11.0


0 visualização