martes, 25 de febrero de 2025

Install Kubernetes Ubuntu

To install kubernetes on ubuntu server, you can install with these scripts on my github or follow the guide.

https://github.com/alegarciadelrio/kubernetes/tree/main/installation-script-ubuntu

 

 

 

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update



sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER newgrp docker
sudo systemctl enable docker
sudo systemctl start docker




Install Kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl 

kubectl version --client
kubectl version --client --output=yaml

 

Install repository

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

 echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list



Install the tools

sudo apt update 

sudo apt install kubeadm kubelet kubectl

sudo apt-mark hold kubeadm kubelet kubectl

kubeadm version









1. Disable all swap spaces with the swapoff command:

sudo swapoff -a

Then use the sed command below to make the necessary adjustments to the /etc/fstab file: sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

2. Load the required containerd modules. Start by opening the containerd configuration file in a text editor, such as nano

sudo vim /etc/modules-load.d/containerd.conf

3. Add the following two lines to the file:

overlay
br_netfilter


4. Next, use the modprobe command to add the modules: 

sudo modprobe overlay
sudo modprobe br_netfilter


5. Open the kubernetes.conf file to configure Kubernetes networking: 

sudo vim /etc/sysctl.d/kubernetes.conf


6. Add the following lines to the file: 

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

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

net.ipv4.ip_forward = 1

sudo sysctl --system


Initialize Kubernetes on Master Node
sudo vim /etc/default/kubelet


Add the following line to the file:

KUBELET_EXTRA_ARGS="--cgroup-driver=cgroupfs"






Reload the configuration
sudo systemctl daemon-reload && sudo systemctl restart kubelet


sudo vim /etc/docker/daemon.json
Append the following

{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}




sudo systemctl daemon-reload && sudo systemctl restart docker

sudo vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

add the following line to the file:

Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"

 

 

 

sudo systemctl daemon-reload && sudo systemctl restart kubelet

Edit the file and comment the following line:

sudo vim /etc/containerd/config.toml

Comment the line that says disable cri.
#disabled_plugins = ["cri"]

 

Restart the service

sudo systemctl restart containerd.service

 

Start the kubeadm.

sudo kubeadm init --control-plane-endpoint=master-node --upload-certs

 

 Try to run

kubectl get all


Then initialize calico

curl https://docs.projectcalico.org/manifests/calico.yaml -O 

curl -O https://calico-v3-25.netlify.app/archive/v3.25/manifests/calico.yaml

kubectl apply -f calico.yaml 

sudo systemctl restart containerd.service

See also:
https://github.com/containerd/containerd/blob/main/script/setup/install-cni

 

If doesn't work.

sudo kubeadm reset

sudo kubeadm init --control-plane-endpoint=master-node --upload-certs

 

Then copy the credentials

mkdir -p $HOME/.kube

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

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


 

Not use docker:
sudo systemctl disable docker

sudo systemctl disable docker.socket

 

 

Run this on the master node:

kubectl taint nodes --all node.kubernetes.io/not-ready-

 kubectl taint nodes --all node-role.kubernetes.io/control-plane-

 

On the node side:

sudo systemctl stop apparmor && sudo systemctl disable apparmor

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update



sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER newgrp docker
sudo systemctl enable docker
sudo systemctl start docker





Install Kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl 

kubectl version --client
kubectl version --client --output=yaml

 

Install repository

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

 echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list



Install the tools

sudo apt update 

sudo apt install kubeadm kubelet kubectl

sudo apt-mark hold kubeadm kubelet kubectl

kubeadm version









1. Disable all swap spaces with the swapoff command:

sudo swapoff -a

Then use the sed command below to make the necessary adjustments to the /etc/fstab file: sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

2. Load the required containerd modules. Start by opening the containerd configuration file in a text editor, such as nano

sudo vim /etc/modules-load.d/containerd.conf

3. Add the following two lines to the file:

overlay
br_netfilter


4. Next, use the modprobe command to add the modules: 

sudo modprobe overlay
sudo modprobe br_netfilter


5. Open the kubernetes.conf file to configure Kubernetes networking: 

sudo vim /etc/sysctl.d/kubernetes.conf


6. Add the following lines to the file: 

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

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

net.ipv4.ip_forward = 1

sudo sysctl --system


Then edit the following file

sudo vim /etc/default/kubelet


Add the following line to the file:

KUBELET_EXTRA_ARGS="--cgroup-driver=cgroupfs"






Reload the configuration
sudo systemctl daemon-reload && sudo systemctl restart kubelet



Edit the hostname to match the other server

sudo vim /etc/hosts

 

Run the command that shows on the deployment of the master node (when you do kubeadm init).

sudo kubeadm join pb-kube-d003:6443 --token iwwfd7.241eota*******     --discovery-token-ca-cert-hash sha256:58f7af701*********************************



Run this on the master node:

kubectl taint nodes --all node.kubernetes.io/not-ready-

 

More info on
https://discuss.kubernetes.io/t/error-while-setting-up-a-clucter-unable-to-join-the-worker-node-please-someone-help-me-im-an-intern-help-me-to-do-this/27096/2

https://phoenixnap.com/kb/install-kubernetes-on-ubuntu

 https://www.linuxtechi.com/install-kubernetes-on-ubuntu-22-04/

 

No hay comentarios:

Publicar un comentario