Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Installing and configuring a K3s edge cluster

Introduction

This content provides a summary of how to install k3s (rancher), a lightweight and small Kubernetes cluster, on Ubuntu Linux AMD64. For more information, see the k3s documentation .

Pre-requisites

  • Architecture must be either x86_64 or arm64
  • Operating system must be modern Linux variant with 64-bit and systemd support

Note: If installed, uninstall kubectl before completing the following steps.

Installing

  1. Either login as root or elevate to root with sudo -i

  2. Confirm that the full hostname of your machine contains at least two dots:

    hostname
    

    If the full hostname of your machine contains fewer than two dots, change the hostname:

    hostnamectl set-hostname <your-new-hostname-with-2-dots>
    

    For more information, see github issue .

  3. Install k3s:

    curl -sfL https://get.k3s.io | sh -
    
  4. Create the image registry service:
    1. Create the persistent volume claim:

      kubectl apply -f https://raw.githubusercontent.com/open-horizon/open-horizon.github.io/master/docs/installing/k3s-persistent-claim.yaml
      
    2. Verify that the persistent volume claim was created and is in โ€œPendingโ€ status

      kubectl get pvc
      
    3. Create the registry deployment and service:

      kubectl apply -f https://raw.githubusercontent.com/open-horizon/open-horizon.github.io/master/docs/installing/k3s-registry-deployment.yaml
      
    4. Verify that the service was created:

      kubectl get deployment
      kubectl get service
      

      Which will issue a response similar to:

      NAME              READY   UP-TO-DATE   AVAILABLE   AGE
      docker-registry   1/1     1            1           21s
      NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
      kubernetes                ClusterIP   10.43.0.1      <none>        443/TCP          3h46m
      docker-registry-service   NodePort    10.43.46.175   <none>        5000:31466/TCP   67s
      
    5. Define the registry endpoint:

      export REGISTRY_ENDPOINT=$(kubectl get service docker-registry-service | grep docker-registry-service | awk '{print $3;}'):5000
      

      To verify that it was set properly:

      echo $REGISTRY_ENDPOINT
      

      Which will respond with something similar to:

      10.43.46.175:5000
      
    6. Add it to K3s configuration:

      cat << EOF >> /etc/rancher/k3s/registries.yaml
      mirrors:
        "$REGISTRY_ENDPOINT":
          endpoint:
            - "http://$REGISTRY_ENDPOINT"
      EOF
      
      

      To verify that it wrote the file properly:

      cat /etc/rancher/k3s/registries.yaml
      

      Which will respond with something similar to:

      mirrors:
        "10.43.46.175:5000":
          endpoint:
            - "http://10.43.46.175:5000"
      
    7. Restart k3s to pick up the change to the K3s configuration:

      systemctl restart k3s
      
  5. Define this registry in Docker as an insecure registry:

    1. Install Docker (if not already installed):

      NOTE: If docker --version responds with a version number, then it is installed.

      curl -fsSL get.docker.com | sh
      
    2. Create or add to /etc/docker/daemon.json (replacing <registry-endpoint> with the value of the $REGISTRY_ENDPOINT environment variable you obtained in a previous step).

      {
        "insecure-registries": [ "<registry-endpoint>" ]
      }
      
    3. Restart Docker to pick up the change:

      systemctl restart docker
      

Whatโ€™s next