Picture this: you’re tasked with deploying Kubernetes on CentOS 7 in record time. Maybe it’s for a pet project, a lab environment, or even production. You’ve heard of k3s, the lightweight Kubernetes distribution, but you’re unsure where to start. Don’t worry—I’ve been there, and I’m here to help. I’ll walk you through setting up k3s on CentOS 7 step by step. We’ll cover prerequisites, installation, troubleshooting, and even a few pro tips to make your life easier. By the end, you’ll have a solid Kubernetes setup ready to handle your workloads.
Why Choose k3s for CentOS 7?
Kubernetes is a fantastic tool, but its complexity can be daunting, especially for smaller setups. k3s simplifies Kubernetes without sacrificing core functionality. Here’s why k3s is a great choice for CentOS 7:
- Lightweight: k3s has a smaller footprint compared to full Kubernetes distributions. It removes unnecessary components, making it faster and more efficient.
- Easy to Install: A single command gets you up and running, eliminating the headache of lengthy installation processes.
- Built for Edge and IoT: It’s perfect for resource-constrained environments like edge devices, Raspberry Pi setups, or virtual machines with limited resources.
- Fully CNCF Certified: Despite its simplicity, k3s adheres to Kubernetes standards, ensuring compatibility with Kubernetes-native tools and configurations.
- Automatic Upgrades: k3s includes a built-in upgrade mechanism, making it easier to keep your cluster updated without manual intervention.
Whether you’re setting up a development environment or a lightweight production cluster, k3s is the ideal solution for CentOS 7 due to its ease of use and reliability. Now, let’s dive into the setup process.
Step 1: Preparing Your CentOS 7 System
Before installing k3s, your CentOS 7 server needs to meet a few prerequisites. Skipping these steps can lead to frustrating errors down the line. Proper preparation ensures a smooth installation and optimizes your cluster’s performance.
Update Your System
First, ensure your system is up to date. This keeps packages current and eliminates potential issues caused by outdated dependencies. Run the following commands:
sudo yum update -y
sudo yum upgrade -y
After completing the updates, reboot your server to apply any pending changes to the kernel or system libraries:
sudo reboot
Set a Static IP Address
For a stable cluster, assign a static IP to your server. This ensures consistent communication between nodes. Edit the network configuration file:
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add or modify the following lines:
BOOTPROTO=none
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
Save the file and restart the network to apply the changes:
sudo systemctl restart network
Verify the static IP configuration using:
ip addr
Disable SELinux
SELinux can interfere with Kubernetes operations by blocking certain actions. Disable it temporarily with:
sudo setenforce 0
To disable SELinux permanently, edit the configuration file:
sudo vi /etc/selinux/config
Change the line SELINUX=enforcing to SELINUX=disabled, then reboot your server for the changes to take effect.
Optional: Disable the Firewall
If you’re in a trusted environment, disabling the firewall can simplify setup. Run:
sudo systemctl disable firewalld --now
Install Required Dependencies
k3s doesn’t require many dependencies, but ensuring your system has tools like curl and wget installed can avoid potential errors during installation. Use:
sudo yum install -y curl wget
Step 2: Installing k3s
With your system prepared, installing k3s is straightforward. Let’s start with the master node.
Install k3s on the Master Node
Run the following command to install k3s:
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -
K3S_KUBECONFIG_MODE="644" flag makes the kubeconfig file readable by all users. This is useful for testing but not secure for production.
By default, k3s sets up a single-node cluster. This is ideal for lightweight setups or testing environments.
Verify Installation
Confirm that k3s is running:
sudo systemctl status k3s
You should see a message indicating that k3s is active and running. Also, check the nodes in your cluster:
kubectl get nodes
Retrieve the Cluster Token
To add worker nodes to your cluster, you’ll need the cluster token. Retrieve it using:
sudo cat /var/lib/rancher/k3s/server/node-token
Note this token—it’ll be required to join worker nodes.
Install k3s on Worker Nodes
On each worker node, use the following command, replacing <MASTER_IP> with your master node’s IP and <TOKEN> with the cluster token:
curl -sfL https://get.k3s.io | \
K3S_URL="https://<MASTER_IP>:6443" \
K3S_TOKEN="<TOKEN>" \
sh -
Verify that the worker node has successfully joined the cluster:
kubectl get nodes
You should see all nodes listed, including the master and any worker nodes.
Step 3: Troubleshooting Common Issues
Even with a simple setup, things can go wrong. Here are some common issues and how to resolve them.
Firewall or SELinux Blocking Communication
If worker nodes fail to join the cluster, check that required ports are open and SELinux is disabled. Use telnet to test connectivity to port 6443 on the master node:
telnet <MASTER_IP> 6443
Node Not Ready
If a node shows up as NotReady, check the logs for errors:
sudo journalctl -u k3s
Configuration Issues
Misconfigured IP addresses or missing prerequisites can cause failures. Double-check your static IP, SELinux settings, and firewall rules for accuracy.
Step 4: Next Steps
Congratulations! You now have a functional k3s cluster on CentOS 7. Here are some suggestions for what to do next:
- Deploy a sample application using
kubectl apply -f. - Explore Helm charts to deploy popular applications like Nginx, WordPress, or Prometheus.
- Secure your cluster by enabling authentication and network policies.
- Monitor the cluster using tools like Prometheus, Grafana, or Lens.
- Experiment with scaling your cluster by adding more nodes.
Remember, Kubernetes clusters are dynamic. Always test your setup thoroughly before deploying to production.
Quick Summary
- k3s is a lightweight, easy-to-install Kubernetes distribution, ideal for CentOS 7.
- Prepare your system by updating packages, setting a static IP, and disabling SELinux.
- Installation is simple, but pay attention to prerequisites and firewall rules.
- Troubleshooting common issues like node connectivity can save hours of debugging.
- Explore, test, and secure your cluster to get the most out of k3s.
I’m Max L, and I believe a well-configured cluster is a thing of beauty. Good luck, and happy hacking!
Tools and books mentioned in (or relevant to) this article:
- Kubernetes in Action, 2nd Edition — Complete K8s guide ($45-55)
- Docker Deep Dive — Practical Docker mastery ($30)
- Learning Helm — Package management for K8s ($40)
📋 Disclosure: Some links are affiliate links. If you purchase through these links, I earn a small commission at no extra cost to you. I only recommend products I have personally used or thoroughly evaluated.
📚 Related Articles
- How to Protect Your Homelab from Dust: A Practical Guide
- Fortifying Kubernetes Supply Chains with SBOM and Sigstore
- Scaling GitOps Securely: Best Practices for Kubernetes Security
📊 Free AI Market Intelligence
Join Alpha Signal — AI-powered market research delivered daily. Narrative detection, geopolitical risk scoring, sector rotation analysis.
Pro with stock conviction scores: $5/mo
Get Weekly Security & DevOps Insights
Join 500+ engineers getting actionable tutorials on Kubernetes security, homelab builds, and trading automation. No spam, unsubscribe anytime.
Delivered every Tuesday. Read by engineers at Google, AWS, and startups.
Frequently Asked Questions
What is k3s and how does it differ from standard Kubernetes?
K3s is a lightweight, certified Kubernetes distribution by Rancher Labs. It packages the entire control plane into a single binary under 100MB, replaces etcd with SQLite by default, and removes legacy and alpha features. It is fully conformant with Kubernetes but optimized for edge, IoT, and resource-constrained environments.
What are the minimum system requirements for k3s?
K3s requires as little as 512MB RAM and 1 CPU core for a server node, making it suitable for Raspberry Pi and small VMs. Agent (worker) nodes need even less. Compare this to standard Kubernetes which recommends 2GB RAM and 2 CPU cores minimum.
How do I install k3s on CentOS 7?
Run the official install script: curl -sfL https://get.k3s.io | sh -. This installs k3s as a systemd service and starts the server automatically. Access your cluster with the kubeconfig written to /etc/rancher/k3s/k3s.yaml.
Can k3s run production workloads?
Yes, k3s is production-ready and used in production by many organizations. For high availability, run multiple server nodes with an external datastore like PostgreSQL or MySQL. It supports all standard Kubernetes features including Helm charts, ingress controllers, and persistent volumes.
References
- k3s Documentation — Official documentation for the lightweight Kubernetes distribution.
- Kubernetes Concepts — Official Docs — Core concepts for understanding Kubernetes architecture.
- k3s System Requirements — Hardware and OS requirements for running k3s.
- RHEL 7 / CentOS 7 Documentation — System administration guides for the CentOS 7 platform.
📧 Get weekly insights on security, trading, and tech. No spam, unsubscribe anytime.
