jueves, 27 de marzo de 2025

How To Expand Ubuntu Filesystem Volume on Hyper-V

 

Steps:

  1. Expand the VDHX file via Hyper-V as mentioned in existing solutions and then inside the VM:

  2. fdisk -l

    See which partition is the current Ubuntu setup - should be obvious based on size (in my case was sda3)

  3. growpart /dev/sda 3

    Note the space as mentioned.

  4. pvresize /dev/sda3

    This is the step which isn't mentioned in a lot of places; its the intemediate step that allows the logical volume extension step work.

  5. lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

    The /dev/ part can seen in the fdisk output from step 1.

  6. resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

    After the prep above, this step now works. Takes a couple of moments and afterwards can verify with df -h that the partition is expanded.

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/

 

lunes, 24 de febrero de 2025

Test kubernetes API connection

 

 Based on this service account to deploy from Azure DevOps

https://github.com/alegarciadelrio/kubernetes/tree/main/service-account-for-eks-azure-devops

 

We can figure out the token and the certificate 

SECRET=deploy-robot-secret
TOKEN=$(kubectl get secret ${SECRET} -n default -o json | jq -Mr '.data.token' | base64 -d) # Extract, decode and write the ca.crt to a temporary location
kubectl get secret ${SECRET} -o json | jq -Mr '.data["ca.crt"]' | base64 -d > /tmp/ca.crt # Get the API Server location
APISERVER=https://$(kubectl -n default get endpoints kubernetes --no-headers | awk '{ print $2 }')


Then you can run the following on your pc:
CA_CERT=ca.crt
TOKEN="wfpZ7Yz7YfsZNwcXOwtXvNQ5Z4OJnSdlcq8vmEsug"
NAMESPACE="dfdfdfd=="
curl --cacert $CA_CERT -H "Authorization: Bearer $TOKEN" "https://host:6443/version"