martes, 25 de febrero de 2025

Install Kubernetes 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






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 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 nano /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

 

 

 

 

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

 

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"


miércoles, 19 de febrero de 2025

git toolbox

 

List all branches

git branch -v -a

 

Delete a branch:

git branch -d local_branch_name
 
 
Force delete branch
git branch -D local_branch_name 

 

Create a branch

git checkout -b newbranch

git checkout commit -m "files modified"

 

Push origin changes to the new branch

git push origin newbranch


Connect to a remote branch:

#git checkout feature/auth0-configuration
branch 'feature/auth0-configuration' set up to track 'origin/feature/auth0-configuration'.
Switched to a new branch 'feature/auth0-configuration'

 

Modify the files that you want:

# git status
On branch feature/auth0-configuration
Your branch is up to date with 'origin/feature/auth0-configuration'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   frontend/Dockerfile

no changes added to commit (use "git add" and/or "git commit -a")

 

# git add frontend/Dockerfile 

 

# git commit -m 'fix: Resolve docker file with env variables.'
[feature/auth0-configuration 76f71d4] fix: Resolve docker file with env variables.
 1 file changed, 5 insertions(+), 10 deletions(-)

 

# git push origin feature/auth0-configuration
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.


To delete all docker images:

docker rmi -f $(docker images -aq)