Kubernetes – Installing and creating a cluster

First you need to install Docker.

For Kubernetes to work correctly, you must disable SWAP

swapoff -a

Also check delete it with fstab

Add Kubernetes repository and install

Ubuntu:

apt update && apt install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF

apt update
apt install -y kubelet kubeadm kubectl

CentOS 7:

cat <<EOF > /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
EOF

setenforce 0

yum install -y kubelet kubeadm kubectl

Add to autorun and run:

systemctl enable kubelet && systemctl start kubelet

 

We initialize the Kubernetes cluster:

kubeadm init --apiserver-advertise-address=1.2.3.4 --pod-network-cidr=10.244.0.0/16 --kubernetes-version stable-1.12
  • --apiserver-advertise-address - sets the IP address to which Kubernetes will broadcast the API, the default is "0.0.0.0"
  • --pod-network-cidr -to use an alternative private network range, the default is "10.96.0.0/12"
  • --kubernetes-version - rigidly sets a specific version for the cluster, the default is "stable-1"

If everything is successful, then you will see something like the following:

Your Kubernetes master has initialized successfully!

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

kubeadm join 1.2.3.4:6443 --token w70rla.kck3wg7lp85x8wlo --discovery-token-ca-cert-hash sha256:ea4a8a533dc61574e7794f7322ae2b29e531fd9f944d7e9f80e367ebd22e4470

As is clear from the conclusion, it is necessary from an ordinary user (if suddenly there is none, create) to do the following:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

If there is no regular user in the system, you must create it with the sudo privilege:

useradd kubernetes -G sudo -m -s /bin/bash

 

Kubectl has autocompletion, for this, the "bash-completion" package must be installed on the system. For the bash shell, do the following:

echo "source <(kubectl completion bash)" >> ~/.bashrc

For MacOS or the zsh shell, see the Kubernetes documentation.

 

Install Flannel:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Restart Kubernetes:

systemctl restart kubelet

 

Add another node to our cluster.

On it, after repeating the installation steps of Docker and Kubernetes, we will start them and that’s all, initialization is done only on the wizard when creating the cluster.

From the root, we will execute the command received at the initialization stage of the cluster:

kubeadm join 1.2.3.4:6443 --token w70rla.kck3wg7lp85x8wlo --discovery-token-ca-cert-hash sha256:ea4a8a533dc61574e7794f7322ae2b29e531fd9f944d7e9f80e367ebd22e4470

Verify that cluster nodes are allowed access on TCP port 6443.

Now, back to the master, and from a regular user, we can see a list of nodes in the cluster:

kubectl get nodes

You can set the role of the node as follows:

kubectl label node NODE_NAME node-role.kubernetes.io/worker=worker
0 0 vote
Article Rating

Tagged: Tags

Подписаться
Уведомление о
guest
0 Comments
Inline Feedbacks
View all comments