The Start To My First Homelab
Welcome to the journey of setting up a self-hosted infrastructure, also known as a homelab. This guide will walk you through creating your initial setup, focusing on automation and open-source.
# The Start To My First Homelab
Welcome to the journey of setting up a self-hosted infrastructure, also known as a homelab. This guide will walk you through creating your initial setup, focusing on automation and open-source technologies, catering to experienced sysadmins and DevOps engineers who aim to enhance their skillset in building and managing their own IT infrastructure.
Prerequisites
To follow along with this tutorial, ensure that you have:
- A system running Ubuntu 20.04 or later (with at least 8GB RAM recommended)
- Sufficient disk space for your VMs and containers (minimum of 50GB free space suggested)
- Docker CE version 5.0.8 or higher installed:
apt install docker-ce=5.0.8
- Kubernetes version 1.20.0 or higher installed:
snap install kubectl --classic
- A text editor like VS Code, Atom, or Nano
Setting Up Docker
Docker will serve as the foundation for our homelab. Let’s start by creating a new user with restricted permissions:
1
2
adduser docker
usermod -aG docker $USER
Next, configure the system to start Docker automatically upon reboot:
1
2
systemctl enable docker.service
systemctl start docker.service
Configuring Docker Compose
Create a docker-compose.yml
file in your preferred text editor and add the following content:
1
2
3
4
5
6
7
8
9
version: '3'
services:
myapp:
image: myapp:latest
ports:
- "8000:80"
environment:
- DB_USER=myuser
- DB_PASSWORD=mypassword
This configuration tells Docker to spin up a container based on the myapp
image, exposing port 8000 and setting two environment variables for database connection details.
Installing Kubernetes
Now, we’ll set up Kubernetes to manage our containers:
Install the Kubernetes server components with this command:
1 2 3
snap install kubeadm --classic snap install kubelet --classic snap install helm --classic
Initialize your Kubernetes cluster using these commands:
1
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Save the output starting with
kubectl
configuration to a file calledkubeconfig.yaml
.Apply the Pod network:
1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Add your user to the
kubectl
configuration:1 2
mkdir -p $HOME/.kube && cp -i /etc/kubernetes/admin.conf $HOME/.kube/config \ && chown $(id -u):$(id -g) $HOME/.kube/config
Verify the installation:
1
kubectl get nodes
Deploying Your First Application with Helm
With Kubernetes set up, we can now deploy our application using Helm:
Create a new Helm chart for your app in a separate directory (e.g.,
myapp
):1
helm create myapp
Modify the
values.yaml
file inside themyapp
folder to include the image name, ports, and environment variables:1 2 3 4 5 6 7 8 9 10 11
image: repository: myapp tag: latest ports: - name: http port: 80 env: - name: DB_USER value: "myuser" - name: DB_PASSWORD value: "mypassword"
Install the Helm chart using this command:
1
helm install myapp ./myapp
Verify the deployment with:
1
kubectl get pods -n default
Troubleshooting
If you encounter issues during setup, check the Docker, Kubernetes, and Helm official documentation for troubleshooting guides.
Conclusion
This guide covered setting up a basic homelab using Docker, Kubernetes, and Helm. As you continue to build your infrastructure, be aware of potential security considerations like restricting network access, implementing strong authentication methods, and keeping your software up-to-date. For performance optimization tips, refer to the official documentation for each tool.
Common pitfalls include misconfigurations leading to data loss or exposure, insufficient hardware resulting in slow performance, and neglecting regular maintenance tasks such as updating images and upgrading components. By following best practices and staying informed about new developments in DevOps, you can create a powerful self-hosted infrastructure that will serve your needs for years to come.