Post

Install Kubernetes On A Single Machine With K3s

K3s is an option for deploying a minimal k8s environment, when a full k8s environment may not be required, for example development and testing.

This deployment method should work on EC2 instances, VMs, and bare-metal servers. It has been tested on Ubuntu 22.04 and Amazon Linux 2.

The following components are deployed:

  • K3s with containerd as the container runtime
  • Ingress nginx
  • Helm
  • Argo CD

Set kubeconfig permissions to be accessible by non-root users

1
export K3S_KUBECONFIG_MODE="644"

Install k3s and without Traefik, ingress-nginx will be used instead

1
curl -sfL https://get.k3s.io | sh -s - --disable traefik

Check k3s service status

1
sudo systemctl status k3s

This should show the k3s service is active and running. This may take a few minutes.

Symlink kubeconfig to default location

1
2
mkdir -p ~/.kube
ln -s /etc/rancher/k3s/k3s.yaml ~/.kube/config

Check node is ready

1
kubectl get nodes

Install helm

1
2
3
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

Deploy Nginx Ingress.

1
2
3
4
5
6
7
8
9
10
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

helm repo update

helm install internal-ingress ingress-nginx/ingress-nginx \
--namespace internal-ingress   \
--create-namespace             \
--set controller.ingressClassResource.name="nginx" \
--set controller.ingressClass="nginx" \
--set controller.defaultBackendService.enabled=true

Set up argo-values.yaml. Remember to escape the $ with a backslash (\$), since cat is used to create this file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cat <<EOF  > argo-values.yaml
global:
  # no domain specified so *:80 is routed to argo through the ingress
  domain: 
configs:
  params:
    # allow non tls
    server.insecure: true

  secret:
    ## Argo expects the password in the secret to be bcrypt hashed. You can create this hash with
    ##  htpasswd -nbBC 10 "" 'password123ABC' | tr -d ':\n' | sed 's/$2y/$2a/'
    argocdServerAdminPassword: "\$2a\$10\$vvKImPs2Bc..vjaeM3sHW.aVADxpLmQmO8XFH/8ZbL0pWonBYwwv2"
    
server:
  ingress:
    enabled: true
    ingressClassName: nginx
    # allow non tls
    tls: false 
EOF

Add argo helm repository

1
helm repo add argo https://argoproj.github.io/argo-helm

Update helm repos

1
helm repo update

Install Argo CD

1
helm install argocd argo/argo-cd -n argocd --create-namespace -f argo-values.yaml

Once deployed argo should be available on http://localhost:80 credentials are admin and password123ABC

After login, change the password to something more secure.

This post is licensed under CC BY 4.0 by the author.