0% found this document useful (0 votes)
241 views

Steps k3s Cluster Configuration

This document provides instructions for configuring multiple nodes to create a Kubernetes cluster using K3s with either an embedded etcd or external PostgreSQL database. It describes setting hostnames, disabling swap, copying configuration files, and installing K3s on one node as the server and others as agents. It also covers configuring services like Traefik and checking the cluster status.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
241 views

Steps k3s Cluster Configuration

This document provides instructions for configuring multiple nodes to create a Kubernetes cluster using K3s with either an embedded etcd or external PostgreSQL database. It describes setting hostnames, disabling swap, copying configuration files, and installing K3s on one node as the server and others as agents. It also covers configuring services like Traefik and checking the cluster status.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

# For every node

sudo hostnamectl set-hostname nodename

# Configure /etc/hosts with node ips


192.168.88.15 node1
192.168.88.16 node2
192.168.88.17 node3

# Disable swap
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo reboot

# Copy regitry configuration


mkdir -p /etc/rancher/k3s/
cp registries.yaml /etc/rancher/k3s/registries.yaml

# Copy k3s binary


cp k3s /usr/local/bin/

# Copy airgap images


#ARCH=amd64
#sudo mkdir -p /var/lib/rancher/k3s/agent/images/
#sudo cp ./k3s-airgap-images-$ARCH.tar /var/lib/rancher/k3s/agent/images/

# Configure k3s datastore etcd (optional)


K3S_DATASTORE_ENDPOINT='https://192.168.88.10:2379'
K3S_DATASTORE_CAFILE='/etc/etcd/etcd-ca.crt'
K3S_DATASTORE_CERTFILE='/etc/etcd/server.crt'
K3S_DATASTORE_KEYFILE='/etc/etcd/server.key'

# Configure k3s datastore postgresql


# On database server

#./appollo-create-database.sh container database


./appollo-create-database.sh postgres-external11 k3s
#./appollo-create-database.sh container user password
./appollo-create-user.sh postgres-external11 k3s testpostgres
#./appollo-create-database.sh container database schema user
./appollo-modify-database-owner.sh postgres-external11 k3s public k3s

user is k3s
password is testpostgres
database is k3s

# Configure node2 as kubernetes master with etcd embeded database


token="d4d8cfa8e5e5d7703b466dddc01d533"
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='server --cluster-init --token
'$token'' ./install.sh

# To use metallb
--no-deploy=servicelb

# To use traefik 2
--no-deploy=traefik

# Configuration with external datastore


token="d4d8cfa8e5e5d7703b466dddc01d700"
K3S_DATASTORE_ENDPOINT='postgres://k3s:[email protected]:5432/k3stest?
sslmode=disable'
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='server --cluster-init --token
'$token' --datastore-endpoint '$K3S_DATASTORE_ENDPOINT' --no-deploy=servicelb'
./install.sh

# With etcd embeded database (optional)


token="d4d8cfa8e5e5d7703b466dddc01d700"
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='server --cluster-init --token
'$token' --datastore-endpoint '$K3S_DATASTORE_ENDPOINT' --datastore-cafile
'$K3S_DATASTORE_CAFILE' --datastore-certfile '$K3S_DATASTORE_CERTFILE' --datastore-
keyfile '$K3S_DATASTORE_KEYFILE'' ./install.sh

# Configure the rest of nodes as kubernetes masters


token="d4d8cfa8e5e5d7703b466dddc01d700"
K3S_DATASTORE_ENDPOINT='postgres://k3s:[email protected]:5432/k3stest?
sslmode=disable'
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='server --server https://node2:6443
--token '$token' --datastore-endpoint '$K3S_DATASTORE_ENDPOINT'' ./install.sh

# With etcd
token="d4d8cfa8e5e5d7703b466dddc01d700"
INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC='server --server https://node2:6443
--token '$token' --datastore-endpoint '$K3S_DATASTORE_ENDPOINT' --datastore-cafile
'$K3S_DATASTORE_CAFILE' --datastore-certfile '$K3S_DATASTORE_CERTFILE' --datastore-
keyfile '$K3S_DATASTORE_KEYFILE'' ./install.sh

# The token should be the same on all cluster nodes. To verify the token
cat /var/lib/rancher/k3s/server/node-token

# K3S log can be found


tail -f /var/log/syslog

# Install agent (This step is optional)


# Get server token
cat /var/lib/rancher/k3s/server/node-token
K107600156b68cb363c9a2457beff2eb94f7d433f0f97cb66016fb73ec151ea453c::server:d4d8cfa
8e5e5d7703b466dddc01d5332

token="K107600156b68cb363c9a2457beff2eb94f7d433f0f97cb66016fb73ec151ea453c::server:
d4d8cfa8e5e5d7703b466dddc01d5332"
k3s_url="https://node2:6443"
INSTALL_K3S_SKIP_DOWNLOAD=true K3S_URL=${k3s_url} INSTALL_K3S_EXEC='agent --server
https://node2:6443 --token '$token'' ./install.sh

# To delete node from cluster


kubectl delete node nodename

# Configure upstream Kubernetes command line tools with the correct kubeconfig path
(This is userd for helm or upstream kubernetes kubectl)
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

# Check cluster status


kubectl cluster-info

# List cluster nodes


kubectl get nodes
# Get kubernetes pods
kubectl get pods --all-namespaces

# To uninstall k3s
k3s-uninstall.sh

# Update traefik config (for traefik 2 optional)


cp traefik-config.yaml /var/lib/rancher/k3s/server/manifests/traefik-config.yaml

# Configure traefik
sudo kubectl apply -f ./CustomeResourceDefinition.yaml

sudo kubectl apply -f ./deployment.yaml

# Configure traefik using helm


helm repo add traefik https://containous.github.io/traefik-helm-chart

You might also like