Skip to content
Snippets Groups Projects
1-2-install-microk8s.md 5.29 KiB
Newer Older
  • Learn to ignore specific revisions
  • # 1.2. Install MicroK8s Kubernetes platform
    
    
    This section describes how to deploy the MicroK8s Kubernetes platform and configure it 
    to be used with ETSI TeraFlowSDN controller.
    Besides, Docker is installed to build docker images for the ETSI TeraFlowSDN controller.
    
    The steps described in this section might take some minutes depending on your internet 
    connection speed and the resources assigned to your VM, or the specifications of your 
    physical server.
    
    
    
    ## 1.2.1. Upgrade the Ubuntu distribution
    Skip this step if you already did it during the creation of the VM.
    ```bash
    sudo apt-get update -y
    sudo apt-get dist-upgrade -y
    ```
    
    
    ## 1.2.2. Install prerequisites
    ```bash
    sudo apt-get install -y ca-certificates curl gnupg lsb-release snapd jq
    ```
    
    
    ## 1.2.3. Install Docker CE
    Install Docker CE
    ```bash
    sudo apt-get install -y docker.io
    ```
    
    Add key "insecure-registries" with the private repository to the daemon configuration. It is done in two commands since
    sometimes read from and write to same file might cause trouble.
    
    ```bash
    if [ -s /etc/docker/daemon.json ]; then cat /etc/docker/daemon.json; else echo '{}'; fi \
        | jq 'if has("insecure-registries") then . else .+ {"insecure-registries": []} end' -- \
        | jq '."insecure-registries" |= (.+ ["localhost:32000"] | unique)' -- \
        | tee tmp.daemon.json
    sudo mv tmp.daemon.json /etc/docker/daemon.json
    sudo chown root:root /etc/docker/daemon.json
    sudo chmod 600 /etc/docker/daemon.json
    ```
    
    Restart the Docker daemon
    ```bash
    sudo systemctl restart docker
    ```
    
    
    ## 1.2.4. Install MicroK8s
    Ref: https://ubuntu.com/tutorials/install-a-local-kubernetes-with-microk8s
    Ref: https://microk8s.io/#install-microk8s
    
    ```bash
    # Install MicroK8s
    sudo snap install microk8s --classic --channel=1.24/stable
    
    # Create alias for command "microk8s.kubectl" to be usable as "kubectl"
    sudo snap alias microk8s.kubectl kubectl
    
    ```
    
    It is important to make sure that `ufw` will not interfere with the internal pod-to-pod
    and pod-to-Internet traffic.
    To do so, first check the status.
    If `ufw` is active, use the following command to enable the communication.
    
    ```bash
    
    
    # Verify status of ufw firewall
    sudo ufw status
    
    # If ufw is active, install following rules to enable access pod-to-pod and pod-to-internet
    sudo ufw allow in on cni0 && sudo ufw allow out on cni0
    sudo ufw default allow routed
    ```
    
    
    ## 1.2.5. Add user to the docker and microk8s groups
    
    
    It is important that your user has the permission to run `docker` and `microk8s` in the 
    terminal.
    To allow this, you need to add your user to the `docker` and `microk8s` groups with the 
    following commands:
    
    
    ```bash
    sudo usermod -a -G docker $USER
    sudo usermod -a -G microk8s $USER
    
    sudo chown -f -R $USER $HOME/.kube
    sudo reboot
    ```
    
    
    In case that the .kube file is not automatically provisioned into your home folder, you 
    may follow the steps below:
    
    
    ```bash
    mkdir -p $HOME/.kube
    sudo chown -f -R $USER $HOME/.kube
    microk8s config > $HOME/.kube/config
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    ## 1.2.6. Check status of Kubernetes and addons
    To retrieve the status of Kubernetes __once__, run the following command:
    
    ```bash
    microk8s.status --wait-ready
    ```
    
    
    To retrieve the status of Kubernetes __periodically__ (e.g., every 1 second), run the 
    following command:
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    ```bash
    watch -n 1 microk8s.status --wait-ready
    ```
    
    
    ## 1.2.7. Check all resources in Kubernetes
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    To retrieve the status of the Kubernetes resources __once__, run the following command:
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    kubectl get all --all-namespaces
    
    To retrieve the status of the Kubernetes resources __periodically__ (e.g., every 1 
    second), run the following command:
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    ```bash
    watch -n 1 kubectl get all --all-namespaces
    ```
    
    
    ## 1.2.8. Enable addons
    The Addons enabled are:
    - `dns`: enables resolving the pods and services by name
    - `hostpath-storage`: enables providing storage for the pods (required by `registry`)
    - `ingress`: deploys an ingress controller to expose the microservices outside Kubernetes
    - `registry`: deploys a private registry for the TFS controller images
    
    ```bash
    microk8s.enable dns hostpath-storage ingress registry
    ```
    
    
    __Important__: Enabling some of the addons might take few minutes.
    Do not proceed with next steps until the addons are ready.
    Otherwise, the deployment might fail.
    To confirm everything is up and running:
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    1. Periodically
       [Check the status of Kubernetes](./1-2-install-microk8s.md#126-check-status-of-kubernetes)
       until you see the addons [dns, ha-cluster, hostpath-storage, ingress, registry, storage] in the enabled block.
    2. Periodically
       [Check Kubernetes resources](./1-2-install-microk8s.md#127-check-all-resources-in-kubernetes)
       until all pods are __Ready__ and __Running__.
    
    
    
    ## 1.2.9. Stop, Restart, and Redeploy
    Find below some additional commands you might need while you work with MicroK8s:
    ```bash
    microk8s.stop  # stop MicroK8s cluster (for instance, before power off your computer)
    microk8s.start # start MicroK8s cluster
    microk8s.reset # reset infrastructure to a clean state
    ```
    
    If the following commands does not work to recover the MicroK8s cluster, you can redeploy it.
    First remove the current deployment as follows:
    ```bash
    sudo snap remove microk8s
    sudo apt-get remove --purge docker.io
    ```
    
    Then, redeploy as it is described in this section.