- Multi-architecture Docker image (ARM64 + AMD64) - Kubernetes manifests for 3-replica deployment - Traefik ingress configuration - NGINX Proxy Manager integration - ConfigMap-based configuration - Automated build and deployment scripts - Session monitoring tools
4.2 KiB
4.2 KiB
Setting Up kubectl for k3s
Since your kubectl config is empty, you need to configure it to connect to your k3s cluster.
Quick Setup (Automated)
cd kubernetes
./setup-kubectl.sh
The script will:
- Ask for your k3s server IP
- Retrieve the kubeconfig from the server via SSH
- Modify it to use the correct server IP
- Save it to your local machine
- Test the connection
Example Run:
$ ./setup-kubectl.sh
Enter k3s server IP address: 192.168.1.101
Enter SSH username for k3s server (default: ubuntu): ubuntu
Fetching kubeconfig from k3s server...
✓ Retrieved kubeconfig from server
Choose how to save the kubeconfig:
1) Replace ~/.kube/config
2) Save as ~/.kube/config-k3s (separate file, safer)
3) Merge with existing ~/.kube/config
Enter choice (1/2/3, default: 2): 2
✓ Saved to ~/.kube/config-k3s
To use this config, run:
export KUBECONFIG=~/.kube/config-k3s
Manual Setup
If you prefer to do it manually:
Step 1: Get kubeconfig from k3s server
# SSH to your k3s server node
ssh ubuntu@192.168.1.101 # use your server IP
# View the kubeconfig
sudo cat /etc/rancher/k3s/k3s.yaml
Step 2: Copy to your local machine
# On your local machine
mkdir -p ~/.kube
# Copy the config (replace 192.168.1.101 with your k3s server IP)
scp ubuntu@192.168.1.101:/tmp/k3s-config.yaml ~/.kube/config-k3s
# Or manually copy the content
nano ~/.kube/config-k3s
# Paste the content from previous step
Step 3: Modify server IP
Edit the file and change the server IP from 127.0.0.1 to your actual k3s server IP:
nano ~/.kube/config-k3s
Change:
server: https://127.0.0.1:6443
To:
server: https://192.168.1.101:6443 # use your actual IP
Step 4: Set KUBECONFIG
export KUBECONFIG=~/.kube/config-k3s
Make it permanent by adding to your shell config:
For bash (~/.bashrc):
echo 'export KUBECONFIG=~/.kube/config-k3s' >> ~/.bashrc
source ~/.bashrc
For zsh (~/.zshrc):
echo 'export KUBECONFIG=~/.kube/config-k3s' >> ~/.zshrc
source ~/.zshrc
For fish (~/.config/fish/config.fish):
echo 'set -gx KUBECONFIG ~/.kube/config-k3s' >> ~/.config/fish/config.fish
Step 5: Test connection
kubectl get nodes
You should see your k3s nodes listed!
Verify Setup
After configuration, verify everything works:
# Check contexts
kubectl config get-contexts
# Should show something like:
# CURRENT NAME CLUSTER AUTHINFO NAMESPACE
# * default default default
# Check nodes
kubectl get nodes
# Should show your k3s nodes:
# NAME STATUS ROLES AGE VERSION
# rpi-master Ready control-plane,master 30d v1.28.2+k3s1
# rpi-worker-1 Ready <none> 30d v1.28.2+k3s1
# rpi-worker-2 Ready <none> 30d v1.28.2+k3s1
# Check cluster info
kubectl cluster-info
Troubleshooting
Cannot connect to k3s server
Error: Unable to connect to the server: dial tcp 192.168.1.101:6443: i/o timeout
Fix:
- Verify the IP address is correct
- Check if port 6443 is accessible:
nc -zv 192.168.1.101 6443 - Check firewall rules on k3s server
- Ensure k3s is running:
ssh ubuntu@192.168.1.101 'sudo systemctl status k3s'
Permission denied
Error: error: You must be logged in to the server (Unauthorized)
Fix:
- The kubeconfig may not have been copied correctly
- Re-run the setup script or manually copy the config again
Wrong server IP
If you need to change the server IP:
nano ~/.kube/config-k3s
# Change the server: line to the correct IP
Next Steps
Once kubectl is configured:
# 1. Configure registry on all k3s nodes
./setup-registry.sh
# 2. Deploy Socktop WebTerm
./deploy.sh
Complete Workflow Example
# Setup kubectl
cd kubernetes
./setup-kubectl.sh
# Enter: 192.168.1.101 (your k3s server IP)
# Choose option 2 (save as separate file)
# Set environment variable for current session
export KUBECONFIG=~/.kube/config-k3s
# Verify connection
kubectl get nodes
# Configure registry
./setup-registry.sh
# Enter all node IPs
# Deploy
./deploy.sh
# Choose namespace: default
# Check status
kubectl get pods -l app=socktop-webterm
# Done!