scieee AI-readable full text Open interactive document viewer

Creation of a Kubernetes Infrastructure

Baró Cayetano, Lluís

Abstract

Nowadays the way of developing applications is evolving, so the target of this project is the creation of a Kubernetes cluster, that is a set of nodes that run containerized applications. So we are going to develop three different cluster scenarios: First of all, we are going to use Docker Compose, that is a tool for defining and running multi-container Docker applications. Secondly, we are going to use Microk8s, a tool for developing production-grade upstream for Kubernetes deployment. Finally, the Kubernetes cluster is going to be nested in LXC containers, that is an operating-system-level virtualization method for running multiple isolated Linux systems on a control host using a single Linux kernel. So what is this project offering? We are offering a simple, powerful and quick way to deploy applications in a server, that are in a secure environment, easy to manage, easy to set up, scalable, cheap and using an open source methodology.

Full text

Creation of a Kubernetes Infrastructure Degree Thesis submitted to the Faculty of the Escola Tècnica d’Enginyeria de Telecomunicació de Barcelona Universitat Politècnica de Catalunya by Lluís Baró Cayetano In partial fulfillment of the requirements for the degree in TELEMATICS ENGINEERING Advisor: Jose Luis Muñoz Tapia Barcelona, January 2021 Abstract Nowadays the way of deploying applications is evolving, so the target of this project is the creation of a Kubernetes cluster, that is a set of nodes that run containerized applications. So we are going to develop three different cluster scenarios: First of all, we are going to use Docker Compose, that is a tool for defining and running multi-container Docker applications. Secondly, we are going to use Microk8s, a tool for developing production-grade upstream for Kubernetes deployment. Finally, the Kubernetes cluster is going to be nested in LXC containers, that is an operating-system-level virtualization method for running multiple isolated Linux systems on a control host using a single Linux kernel. So what is this project offering? We are offering a simple, powerful and quick way to deploy applications in a server, that are in a secure environment, easy to manage, easy to set up, scalable, cheap and using an open source methodology. 2 Resum Avui en dia la forma de desplegar aplicacions està evolucionant, de manera que l’objectiu d’aquest projecte és la creació d’un clúster Kubernetes, que és un conjunt de nodes que executen aplicacions en contenidors. Per tant, les aplicacions es desenvoluparan en tres escenaris: En primer lloc, utilitzarem Docker Compose, que és una eina per definir i executar aplicacions Docker multi-contenidor. En segon lloc, utilitzarem Microk8s, una eina per desenvolupar a nivell de producció per al desplegament de Kubernetes. Finalment, el clúster de Kubernetes s’integrarà en contenidors LXC, que és una virtualització a nivell de sistema operatiu per executar diversos sistemes Linux aïllats en un amfitrió de control mitjançant un sol nucli Linux. Per tant, què ofereix aquest projecte? Oferim una manera senzilla, potent i ràpida de desplegar aplicacions a un servidor, les quals es troben en un entorn segur, fàcil de gestionar, fàcil de configurar, escalable, barat i mitjançant una metodologia de codi obert. 3 Resumen Hoy en día la forma de implementar aplicaciones está evolucionando, por lo que el objetivo de este proyecto es la creación de un clúster de Kubernetes, que es un conjunto de nodos que ejecutan aplicaciones en contenedores. Las aplicaciones se van a desarrollar en tres escenarios: En primer lugar, vamos a utilizar Docker Compose, que es una herramienta para definir y ejecutar aplicaciones Docker en varios contenedores. En segundo lugar, vamos a utilizar Microk8s, una herramienta para desarrollar a nivel de producción la implementación de Kubernetes. Finalmente, el clúster de Kubernetes se anidará en contenedores LXC, que es un método de virtualización a nivel de sistema operativo para ejecutar múltiples sistemas Linux aislados en un host de control utilizando un solo kernel de Linux. Entonces, ¿qué ofrece este proyecto? Ofrecemos una forma simple, potente y rápida de implementar aplicaciones en un servidor, que se encuentran en un entorno seguro, fácil de administrar, fácil de configurar, escalable, económico y con una metodología de código abierto. 4 Acknowledgements This TFG project has a very deep and detailed information about Kubernetes, that has been possible since different people have worked on this information: Jose Luis Muñoz, who is a teacher from the ETSETB doctorate in Networks, as the supervisor, has given the advice during development. At the same time he was one of the beta testers and has done a functional review of all the documentation. Jesús López, who is a student from ETSETB UPC, as a co-worker, has been another developer of the information. Finally Rafa Genés, who is a PhD student from ISG, has been another beta tester of my code. In addition, he has done a functional review of the thesis with my supervisor. 5 Revision history and approval record Revision Date Purpose 0 07/12/2020 Document creation 1 03/01/2021 Document language revision 2 04/01/2021 Document content revision 3 20/01/2021 Delivery document DOCUMENT DISTRIBUTION LIST Name e-mail Lluís Baró Cayetano [email protected] Jose Luis Muñoz Tapia [email protected] Rafa Genés Durán [email protected] Written by: Reviewed and approved by: Date 07/12/2020 Date 20/01/2021 Name Lluís Baró Cayetano Name Jose Luis Muñoz Tapia Position Project Author Position Project Supervisor 6 Contents List of Figures 9 List of Tables 10 1 Introduction 12 1.1 Statementofpurpose.............................. 12 1.2 Requirements and specifications. . . . . . . . . . . . . . . . . . . . . . . . 12 1.3 Methods and procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.3.1 Software................................. 13 1.3.2 Documentation............................. 14 1.3.3 Communication............................. 14 1.4 Work plan with tasks, milestones and a Gantt diagram. . . . . . . . . . . . 14 1.4.1 WorkPackages ............................. 15 1.4.2 Milestones................................ 16 1.4.3 GanttDiagram............................. 17 1.5 Deviations from the initial plan and incidences. . . . . . . . . . . . . . . . 17 1.5.1 Planchanges .............................. 17 1.5.2 Incidences................................ 17 2 State of the art of the technology used or applied in this thesis: 19 2.1 ContainerDeployment ............................. 19 2.2 Docker...................................... 20 2.2.1 DockerCompose ............................ 20 2.3 Kubernetes ................................... 21 2.3.1 Kubectl ................................. 21 2.3.2 Helm................................... 21 2.3.3 Microk8s ................................ 22 2.4 LXDContainers ................................ 23 3 Methodology: 24 3.1 Communication................................. 24 3.2 Software..................................... 24 3.2.1 Git.................................... 24 3.2.2 DockerCompose ............................ 25 3.2.3 Microk8s ................................ 25 3.2.4 LXD................................... 25 3.3 Documentation ................................. 25 4 Project Development: 26 4.1 SelectedApplications.............................. 26 4.2 DesiredCluster................................. 27 4.3 Docker Compose Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.3.1 Creating an Application using Docker Compose: XWiki . . . . . . . 29 4.3.2 Integration of the Services . . . . . . . . . . . . . . . . . . . . . . . 31 7 4.4 KubernetesCluster............................... 32 4.4.1 Creating an Application using Microk8s . . . . . . . . . . . . . . . 32 4.4.2 Integration of the Services . . . . . . . . . . . . . . . . . . . . . . . 34 4.5 Nested LXC Container Kubernetes Cluster . . . . . . . . . . . . . . . . . . 34 4.5.1 Creating LXC Containers . . . . . . . . . . . . . . . . . . . . . . . 36 5 Results 37 5.1 Docker Compose Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.2 KubernetesCluster............................... 38 5.3 Nested LXC Container Kubernetes Cluster . . . . . . . . . . . . . . . . . . 40 6 Budget 43 7 Costs 43 8 Environmental Impact 46 9 Conclusions 47 10 Future Work 47 References 48 8 Listings List of Figures 1 Project’s Gantt diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2 ContainerEvolution .............................. 19 3 Useful Docker Compose Commands . . . . . . . . . . . . . . . . . . . . . . 20 4 Useful Kubectl Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5 UsefulHelmCommands ............................ 22 6 Useful Microk8s Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 22 7 LXC Commands: Useful Commands . . . . . . . . . . . . . . . . . . . . . 23 8 DesiredCluster................................. 28 9 Config files of the Desired Cluster . . . . . . . . . . . . . . . . . . . . . . . 29 10 Docker Compose Example: XWiki YAML file . . . . . . . . . . . . . . . . 30 11 Docker Compose Example: XWiki Environmental Variables . . . . . . . . 30 12 Docker Compose Command: Start Application . . . . . . . . . . . . . . . . 31 13 Docker Compose Command: Status of XWiki Application . . . . . . . . . 31 14 Docker Compose Example: XWiki Home Page . . . . . . . . . . . . . . . . 31 15 Docker Compose Command: Create a Network . . . . . . . . . . . . . . . . 32 16 Docker Compose Networks Example: Updated YAML file . . . . . . . . . . 32 17 Microk8s Command: Enable Addons . . . . . . . . . . . . . . . . . . . . . 32 18 Helm Command: Add Repo . . . . . . . . . . . . . . . . . . . . . . . . . . 33 19 Helm Command: Install XWiki . . . . . . . . . . . . . . . . . . . . . . . . 33 20 Kubectl Command: Cluster Status XWiki . . . . . . . . . . . . . . . . . . 33 21 Kubernetes Cluster: XWiki Home Page . . . . . . . . . . . . . . . . . . . . 34 22 Nested LXC Cluster: Structure . . . . . . . . . . . . . . . . . . . . . . . . 35 23 Nested LXC Cluster: Structure Example . . . . . . . . . . . . . . . . . . . 35 24 LXC Command: Creating a Container . . . . . . . . . . . . . . . . . . . . 36 25 LXC Command: Creating Microk8s profile . . . . . . . . . . . . . . . . . . 36 26 Microk8s Command: Adding a node to a Cluster . . . . . . . . . . . . . . 36 27 Docker Compose: Cluster Status . . . . . . . . . . . . . . . . . . . . . . . 37 28 Docker Compose Cluster: Proxy Hosts . . . . . . . . . . . . . . . . . . . . 38 29 Kubernetes Cluster: Deployments . . . . . . . . . . . . . . . . . . . . . . . 39 30 Kubernetes Cluster: Pods . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 31 Kubernetes Cluster: Services . . . . . . . . . . . . . . . . . . . . . . . . . . 40 32 Kubernetes Cluster: Ingresses . . . . . . . . . . . . . . . . . . . . . . . . . 40 33 CreationofaZpool............................... 41 34 Nested LXC Kubernetes Cluster: Nodes . . . . . . . . . . . . . . . . . . . 41 35 Nested LXC Kubernetes Cluster: Ingresses . . . . . . . . . . . . . . . . . . 41 36 Nested LXC Kubernetes Cluster: Hosts of Devops . . . . . . . . . . . . . . 42 37 Nested LXC Kubernetes Cluster: Mattermost Application . . . . . . . . . 42 38 StateofdevopsZpool ............................. 42 9 Project: Documentation WP ref: 6 Major Constituent: Documentation Short description: Write documentation files such as the Project Proposal, the Critical Review, the Thesis, the Presentation and slides about Kubernetes for an academic purpose. Start date: 20/07/2020 End date: 15/01/2020 Table 6: WP 6 1.4.2 Milestones WP Short Line Milestone / deliverable Date (week) 1 Docker slides Initial Docker slides 2 1 Docker slides Update Docker slides 4 1 Docker slides Final Docker slides 5 2 Kubernetes slides Initial Kubernetes slides 3 2 Kubernetes slides Update Kubernetes slides 6 2 Kubernetes slides Final Kubernetes slides 10 3 Docker Applications Adminer 2 3 Docker Applications Nginx Proxy Manager 3 3 Docker Applications Redmine 4 3 Docker Applications OpenLDAP 4 3 Docker Applications XWiki 5 3 Docker Applications Jitsi 6 3 Docker Applications Nextcloud 7 3 Docker Applications Mattermost 8 3 Docker Applications GitLab 9 3 Docker Applications Readme with the app config 10 4 Kubernetes Cluster Adminer 9 4 Kubernetes Cluster Redmine 10 4 Kubernetes Cluster OpenLDAP 10 4 Kubernetes Cluster XWiki 11 4 Kubernetes Cluster Jitsi 12 4 Kubernetes Cluster Nextcloud 12 4 Kubernetes Cluster Mattermost 13 4 Kubernetes Cluster GitLab 14 4 Kubernetes Cluster Readme with the app config 16 5 LXC Container K8s cluster in a nested LXC container 18 6 Documentation Project Proposal 3 6 Documentation Critical Review 6 6 Documentation Thesis 24 6 Documentation Presentation 26 Table 7: Milestones 16 1.4.3 Gantt Diagram Phases of the Project 2020 2021 Jul. Aug. Sep. Oct. Nov. Dec. Jan. Planning Defining objectives Set up workspace Research Docker Kubernetes Development Docker Apps Kubernetes LXC Containers Documentation Project Proposal Critical review Degree Thesis Annexes Presentation Figure 1: Gantt diagram of the project 1.5 Deviations from the initial plan and incidences. 1.5.1 Plan changes At first, the project was thought to deploy the OpenVPN application in order to implement an extra layer of security. This way applications like Adminer, Nginx Proxy Manager and OpenLDAP are only possible to be configured from the inside. But, in the middle of the project, we realised that this feature was very ambitious and was not really necessary for the development of the other applications. So in the course of this project the applications have been deployed, but the extra security layer will be incorporated in short-term. 1.5.2 Incidences The main incidence of the project was to acquire the vast amount of information that is evolving all the time. As we know Kubernetes was released 6 years ago, on June of 2014 and since that day it is in constant development being the last release on December of 2020. So every day it is evolving with new features and improvements and this makes us to be alert of them and adapt to it. 17 Another problem that occurred during the project was the failure of the nested LXC Containers. We had many problems that we needed to resolve in order to create the cluster. First of all we could not install anything inside the containers because we get an error of insufficient permissions to use AppArmor, that is a Linux kernel security module that allows the system administrator to restrict programs’ capabilities with per-program profiles. The second problem was the creation of zpools using ZFS, that combines the features of a file system and a volume manager, so we could not create the pools inside the containers due to memory problems, as the default zpool defaults to 20% of the size of the partition behind /var/lib/lxd with a minimum size of 15GB and maximum size of 100GB, so the memory left was filling up and there was not enough left. And the third and final problem was another time the AppArmor profiles for microk8s, that without them we could not install microk8s on the desired container. 18 2 State of the art of the technology used or applied in this thesis: The traditional way of deploying an application on a server is becoming to be outdated. To deploy an application, first of all you need that the server to be properly configured, and this means that the application is probably hard wired to the environment. Although validating completely the configuration is nearly impossible because developers do not even have control over what the live environment looks like, we still can access it via SSH and configure some parts of it. This means that the majority of deployments need to be performed in the right way for it to succeed. That is why we need a different way of deployment. Nowadays the way of deploying applications is evolving and no longer is required to spend a lot of time and effort doing it. So here it comes the containerized deployment, where the deployments of applications becomes very simple and brief. In the next sections a brief concept of the technology used in the project is going to be explained, even though an annex with the complete information is attached. 2.1 Container Deployment Containers are a form of operating system virtualization, an abstraction at the application layer which packages codes and dependencies together however they do not contain operating system images. A single container might be used to run anything from a small service or software process to a larger application. Also the use of containers allows to deploy applications regardless of where are they going to be deployed, in a personal environment, public cloud ot private data center. The next figure represents the evolution of the different ways of deploying an application, being the Container Deployment the way that is on rise. Figure 2: Container Evolution 19 The deployment of containers uses management software that simplifies the launch and updates of applications. Container deployment provides fast access to environments and speeds up development because secure containers can be quickly downloaded and put to use. Container deployment also minimizes errors because it reduces the number of moving parts in development. In larger application deployments, multiple containers may be deployed as one or more container clusters. Such clusters might be managed by a containers orchestrators such as Kubernetes or Docker. 2.2 Docker Docker is defined by their creators as: “an open source project to pack, ship and run any application as a lightweight container” The Docker goal is to provide a comprehensive abstraction layer that allows developers to containerize or package any application and have it run on any infrastructure. To do so, Docker uses container technology which provides a “light” form of virtualization. So with Docker you can deploy multiple containers that run on the same operating system. This provides a benefit not offered by virtual machines, considering that using a virtual machine requires running an entire guest operating system to deploy a single application. 2.2.1 Docker Compose Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Also creates a default network to communicate with the containers. With the YAML file, we can define multiple objects like services, networks, and volumes, so it can be defined a multi-container application in a single file. Using Compose is basically a three-step process: 1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere. 2. Define the services (containers) that make up your app in docker-compose.yaml so they can be run together in an isolated environment. 3. Run docker-compose up and compose starts and runs your entire app. The most useful commands are represented below. $ docker -compose up -d # Start the docker container in the background $ docker ps -a # Show all containers running $ docker -compose down # Remove containers in the repository $ docker exec -it :container_id bash # Terminal into the docker container $ docker -compose logs # Show log of the container in the repository Figure 3: Useful Commands of Docker Compose 20 2.3 Kubernetes Kubernetes is an open source orchestration system for containers that allows us to manage containers on a cluster of machines for high availability. So a Kubernetes cluster is a set of nodes that run containerized applications. So in this way, Kubernetes clusters allow applications to be more easily developed, moved and managed. The main features of Kubernetes are: 1. Provide high availability for containers: check health and restart failed containers. 2. K8s must manage how to distribute the load among nodes. 3. Is autoscalable, a cluster can start with one node and expand to thousands. 4. You can run Kubernetes anywhere: on-premise (own datacenters), public cloud (google cloud, AWS, ...) or hybrid public-private. 2.3.1 Kubectl The kubectl is the Kubernetes command-line tool to talk to clusters. The configuration of kubectl is also in /.kube/config, where we can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the –kubeconfig flag. These are the most used commands of Kubectl are: $ kubectl config view # To view information about the cluster $ kubectl create -f file.yaml # Create a k8s object from file $ kubectl get {k8s object} # Display one or many k8s object $ kubectl expose {k8s object} # Expose a k8s object as a new service $ kubectl delete {k8s object} # Delete a k8s object $ kubectl apply -f file # Apply a configuration to a k8s object by file $ kubectl scale --replicas=# {k8s object} # Set a new size of a k8s object $ kubectl describe {k8s object} name # Get information about a k8s object $ kubectl exec -it myPod -- /bin/bash # Terminal into the Pod Figure 4: Useful Commands of Kubectl 2.3.2 Helm Helm is a package manager for kubernetes, like apt or npm. In K8s, you have to configure a lot of YAML files to create a k8s application, so Helm provides a convenient way for packaging collections of manifest (YAML files) and distribute them in public and private registries. Helm uses Charts, that is a set of files that allow easily creating a bundle of Kubernetes deployment manifests. So Helm Charts help to define, install and upgrade complex Kubernetes applications and can be versioned. And the most used commands of are: 21 $ helm search hub/repo <chart > # Search a release in the hub/repo $ helm repo add myName repoLink # Add a chart repository $ helm repo update # Get the latest list of charts $ helm repo list # List the repositories $ helm install myName <chart > # Install a release $ helm uninstall myName # Uninstall a release $ helm list # Get the installed charts $ helm upgrade myName <chart > # Uninstall a release Figure 5: Useful Commands of Helm 2.3.3 Microk8s Microk8s is the simplest, lightweight and focused production-grade upstream for Kubernetes deployment that runs entirely on your workstation or edge device supported by Canonical, with a single command can be installed and easy to maintain. It is especially made for DevOps and perfect for IOT, developer machines or Raspberry Pi. Also there are the Microk8s addons, that provide us all the tools needed to develop the Kubernetes cluster. For example we used RBAC: enables the Role Based Access Control for authorization, Storage: create a default storage class which allocates storage from a host directory, Dashboard: the standard Kubernetes Dashboard, DNS: deploys CoreDNS (DNS server) , Ingress: a simple ingress controller for external access, Helm3: installs the Helm 3 package manager, and Metallb: deploys the MetalLB Loadbalancer. Another useful thing about microk8s is that we can use our host’s commands like Kubectl and Helm. This is because we can export the configuration of Microk8s and also we are able to use Lens, an IDE for Kubernetes, so it helps us to deal with Kubernetes clusters. And these are the most useful commands to use Microk8s: $ microk8s start # Start the cluster $ microk8s stop # Stop the cluster $ microk8s status # Show the status of the cluster $ microk8s enable <addon > # Enabling addons $ microk8s add -node # Adding a node to the cluster $ microk8s join <master >:<port >/<token > # Joining to a remote cluster $ microk8s leave # Remove the node from the cluster $ microk8s kubectl ... # Using Kubectl commands $ microk8s helm3 ... # Using Helm commands Figure 6: Useful Commands of Microk8s 22 Finally we noted that running a VNC is so important, because it offers the possibility to create clusters inside a machine without affecting the machine directly, so we are going to use the LXD Containers. 2.4 LXD Containers LXD is a next generation system container manager. It offers a user experience similar to virtual machines but using Linux containers instead. So with this tool we are able to create LXC containers in order to create a kubernetes cluster in a nested container. As LXD isn’t a rewrite of LXC, we are using LXC commands to create the instances: containers or virtual machines, and the most useful commands are showed in the next figure. $ lxd init # Initial configuration $ lxc launch imageserver:imagename myInstance # Launch an Instance $ lxc list # List all Instances $ lxc start/stop myInstance # Start/Stop a Container $ lxc exec myInstance bash # Shell/Terminal inside Container $ lxc file pull myInstance/container -path host -path # Copy from an instance to host $ lxc file push host -path myInstance/container -path # Copy from host to instance $ lxc delete myInstance # Remove instance $ lxc profile create myProfile # Create Profile $ lxc profile assign myInstance myProfile # Assign Profile $ lxc config show myInstance # Show the configuration of an Instance Figure 7: Useful Commands of LXC So what is this project offering? We are offering a simple, powerful and quick way to deploy applications in a single server, that are in a secure environment, easy to manage, easy to set up, scalable, cheap and using an open source methodology. 23 3 Methodology: In this section there is a detailed explanation about the methodology followed when communicating with the tutor and team mates. Also, it includes a description about the software used develop the project and how it was shared with the supervisor. At the end, there is the procedure of creating the work documentation. So as this project is based on an Open Source Ideology, with optimized solutions based on community knowledge sharing and a DevOps methodology for creating software, so it is based in the integration between software developers and system administrators. 3.1 Communication As it was stated in the introduction, remote communications had been the main way of communicating during the development of the project. These meetings were crucial to discuss the progress and the improvements. At first, it was very comfortable, especially when the supervisor was able to explain all we need to know about Docker and Kubernetes and provided us with some Udemy courses to learn about the matter. In addition, we had meetings during the process of development through remote conversations. On the other hand, thanks to a VNC machine enabled in the server, which will go into detail in the software part, the group could make audio meetings through Jitsi and share the desktop of the virtual machine, so apart from speaking this tool let the team work on the same screen. 3.2 Software This project uses different applications and software developed by other authors, like Docker, Microk8s and Git and the development of the different applications that take part in the cluster. Also we have been using Git in order to share the software developed and the documentation created. 3.2.1 Git The supervisor decided to use Git as a method of sharing the software and the documentation, so we where provided with a VNC machine on the server of the networking department. In the machine a certificate was generated in order to get access to it and configure a Git repository with the code. So, I could work with my personal computer locally in the project and make uploading updates ”commits”. 24 Also, the tutor had access to the repository, so he could download the code and check the updates and improvements daily. This development environment let the supervisor to add new co-workers easily in order to contribute in the development of the project. 3.2.2 Docker Compose Docker Compose has been used in order to create the Docker Cluster and we have worked with it creating different YAML files to store all the configurations for the different applications used. The YAML files where edited directly from the terminal, we used a text editor without graphical interface, Nano, which is included in the official Ubuntu repository. This tool was useful because we only need to create a single YAML file with concrete specifications for each application. 3.2.3 Microk8s We used Microk8s to be able to create the Kubernetes cluster and because it provides us a lot of addons and is the best tool to orchestrate a Kubernetes cluster. The most useful thing about microk8s is that it integrates the use of Kubectl and Helm and we only need one tool to manage the cluster. 3.2.4 LXD LXD is a next generation system container manager. So with this tool we are able to create LXC containers in order to create a kubernetes cluster in a nested container. 3.3 Documentation In the documentation part has been followed a simple way, although maintaining the philosophy of free software, so all the documentation has been written with L A T EXand LibreOffice. Once all the documentation was done, it was sent to the supervisor for validation. Finally, when the documents were approved by the tutor a pdf version was print and uploaded in the UPC Moodle service. In order to share all the documentation with the supervisor, he created a Git repository in a server provided by the networking department, so all the files were saved there in its editable version and in PDF. Finally, the next documentation tasks that have to be done is the realization of a paper, which will be done in Latex language and will be shared in the git repository. Finally, some small Presentation or ”.txt” documents have been created to document pending tasks, installation configurations or doubts towards the supervisor or to some collaborator. 25 $ docker network create --driver=bridge --subnet =172.31.0.0/16 --gateway =172.31.0.1 devops Figure 15: Docker Compose: Creation of a Network After we created a network called devops, we need to configure this network to all the YAML files of the different applications so they can resolve each other by name or alias. Containers connected to the same user-defined bridge network automatically expose all ports to each other (no ports to the outside world). 1networks: 2devops: 3external:true Figure 16: Updated YAML file to provide Communication Between Applications So now the containerized applications are able to talk between them through the container name. 4.4 Kubernetes Cluster To create the Kubernetes Cluster we are going to use Microk8s, as explained before, is the simplest, lightweight and focused production-grade upstream for Kubernetes deployment. Microk8s provides us all the tools necessary to create the cluster, the most important one being Helm, that is a package manager for K8s (like apt or npm), so it provides a convenient way for packaging collections of manifest, YAML files, and distribute them in public and private registries. In order to use Microk8s we have to enable our desired capabilities such as RBAC, Dashboard, Storage, Ingress, DNS, Helm3 and Metallb. Once all of it are enabled we can start the deployment of our first application. 4.4.1 Creating an Application using Microk8s We are going to deploy the same application as before, XWiki, and we are going to use Helm. This way it will be super easy to achieve it. As commented earlier, we need to enable Microk8s addons with this command: $ microk8s enable rbac dashboard storage ingress dns helm3 metallb:(IP Range) Figure 17: Enabling addons in microk8s 32 The advantatge of using Helm is that we are going to deploy XWiki only using a single command and modifying its configuration parameters. To deploy it we are going to use the next steps described in the XWiki Helm Chart[3]. We are going to install the chart, and to do so, first we need to add the keyporttech helm repo and update our repos. $ microk8s helm3 repo add keyporttech https:// keyporttech.github.io/helm -charts/ $ microk8s helm3 repo update Figure 18: Adding XWiki Helm Chart Repo Then we can install easily install it with the next command: $ microk8s helm3 install xwiki keyporttech/xwiki Figure 19: Installing XWiki To check if the application is running, we have to check the K8s cluster with kubectl and wait until the deployment is ready, like in the figure. $ microk8s kubectl get all NAME READY STATUS RESTARTS AGE pod/xwiki -postgresql -0 1/1 Running 0 2d pod/xwiki -xwiki -7f868db4b -5h79f 1/1 Running 0 2d NAME TYPE CLUSTER -IP EXTERNAL -IP PORT(S) AGE service/kubernetes ClusterIP 10.152.183.1 <none > 443/TCP 2d4h service/xwiki -xwiki ClusterIP 10.152.183.200 <none > 80/TCP 2d service/xwiki -postgresql ClusterIP 10.152.183.39 <none > 5432/TCP 2d NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xwiki -xwiki 1/1 1 1 2d NAME DESIRED CURRENT READY AGE replicaset.apps/xwiki -xwiki -7f868db4b 1 1 1 2d NAME READY AGE statefulset.apps/xwiki -postgresql 1/1 2d Figure 20: Cheking the status of the cluster Now we can access the Cluster IP and the port, http://10.152.183.200:80, in a web browser, and after some configurations we expect to obtain the next result. 33 Figure 21: Home Page of XWiki 4.4.2 Integration of the Services In the Kubernetes Cluster the integration of the services require more configurations as the services can be deployed in different nodes that form the cluster. So to integrate all the services in the cluster we needed to configure a K8s object called Service. We need to recall that in K8s all the Pods have an IP that can be used for direct communications without NAT. So in theory, you could talk to these pods directly, but what happens when a node dies? The pods die with it and the Deployment will create new ones, with different IPs. So this is the problem a Service solves. Service is an abstract way to expose an application running on a set of Pods as a network service and when created, each Service is assigned a unique IP address. This address is tied to the lifespan of the Service, and will not change while the Service is alive. This way, Pods can be configured to talk to the Service, and know that communication to the Service will be automatically load-balanced out to some pod that is a member of the Service. And to make all of this possible we need another K8s object to expose the Services, and here comes to work Ingress. Ingress sits in front of multiple services and act as a ”smart router” or entrypoint into your cluster. Is very useful if you want to expose multiple services under the same IP address. While Loadbalancers are L4 devices, Ingress is a L7 proxy (typically HTTP/HTTPS), so it provides external access with features like: Load Balancing, SSL termination, Name-based virtual hosting or URL re-writing and more. 4.5 Nested LXC Container Kubernetes Cluster In terms of an educational method, we want to accomplish this cluster, because this way it will be easy for different developers to work in different machines and have their own cluster, and it will reduce the hardware need it. 34 So a nested LXC Kubernetes Cluster is simple, we want to create a k8s cluster inside a LXC container that is hosted by another LXC container, as shows the figure below. SERVER Kubernetes Cluster Node 1 (LXC Container) Node 2 (LXC Container) Node 3 (LXC Container) Node X (LXC Container) LXC Container 1 Kubernetes Cluster Node 1 (LXC Container) Node 2 (LXC Container) Node 3 (LXC Container) Node X (LXC Container) Kubernetes Cluster Node 1 (LXC Container) Node 2 (LXC Container) Node 3 (LXC Container) Node X (LXC Container) LXC Container 2 Kubernetes Cluster Node 1 (LXC Container) Node 2 (LXC Container) Node 3 (LXC Container) Node X (LXC Container) Kubernetes Cluster Node 1 (LXC Container) Node 2 (LXC Container) Node 3 (LXC Container) Node X (LXC Container) LXC Container X Kubernetes Cluster Node 1 (LXC Container) Node 2 (LXC Container) Node 3 (LXC Container) Node X (LXC Container) Figure 22: Structure of the Nested LXC Cluster So we are going to deploy the same k8s cluster as we developed previously for the Kubernetes Cluster. This cluster is going to be located in a nested LXC container as represents the next figure. Devops is going to be a LXC container that hosts the nodes, also LXC containers, that are going to form the Kubernetes Cluster. Figure 23: Structure of our Example 35 4.5.1 Creating LXC Containers In order to deploy the cluster, we need to create the scenario and to do so we need some configurations. First of all we need to install LXD in our host and create a LXC container, in our case is defined as Devops. To do so we are creating it with the next commands: $ snap install lxd $ lxd init $ lxc launch ubuntu:20.04 devops Figure 24: Creating a LXC Container Also we need to create the profile for microk8s that are going to use the nodes containers, which is going to be inherited from the host. $ lxc profile create microk8s $ wget https://raw.githubusercontent.com/ubuntu/microk8s/master/tests/lxc/microk8s -zfs.profile \ -O microk8s.profile $ cat microk8s.profile | lxc profile edit microk8s $ lxc profile assign devops default,microk8s Figure 25: Creating the microk8s profile Then inside the LXC container, Devops, we are going to create the nodes of the cluster, and we are going to do the same as before, create the profile and then create the containers. To create the multi-node Cluster, we are going to add node-02 to the node-01 and to do so, we are going to use the next microk8s commands Node -01# microk8s add -node microk8s join 10.234.156.79:25000/72 b949125b30d2801955db837ef26020 ... Node -02# microk8s join 10.234.156.79:25000/72 b949125b30d2801955db837ef26020 Figure 26: Adding a node to the cluster Once the first container is initialized, node-01, we are going to follow the same procedure to develop the Kubernetes Cluster using microk8s, and so on for the rest of the nodes. Note that we only need to enable the addons for the rest of the nodes, and in one node we can deploy all, that is going to automatically choose in which node will the pods be deployed. So now we are able to deploy the same cluster as in the Kubernetes Cluster section. 36 5 Results The final result of this TFG project is the creation of three different clusters using different technologies, Docker Compose and Microk8s. Also at the end of the document there are attached the Docker and Kubernetes slides for an academic purpose and a guide to develop the recreated clusters. This guide consists of configuration files and instructions to make it easy for any people that want to develop the same applications or for the collaboration of new students. In this section, there is a brief summary about the three clusters and the the basic configuration of each one. All the detailed information of the procedure or the specific settings can be found in the documentation attached to this project. In addition, there is also a technical explanation of how each functionality has been performed. 5.1 Docker Compose Cluster The Docker Cluster has been deployed with almost all the applications that we desired. The only application we could not develop was OpenVPN. That does not mean that the application is not working, the issue was that we were no capable of configuring the VPN server to establish a TAP interface connection in order to access all the services of the cluster. As we can see, with a simple command we can know what is the status of the services running inside our Docker cluster and which ports of the Host are exposed to the exterior and which are the internal ports for each Docker Application. Figure 27: Docker Compose Cluster Status As we can observe the applications hosted are not not exposing any ports of the host, only Nginx and Jitsi applications, because they need it to work. We can access the applications via the created network for the cluster and its going to gain access through the FQDN, that are the names showed above, like redmine_redmine_1 and the port of the container. 37 To show in a more visual way, the next figure shows all the Proxy Hosts configured with Nginx Proxy Manager, that host the web applications of the other services deployed in the cluster. Figure 28: Proxy Hosts of the Docker Cluster 5.2 Kubernetes Cluster To deploy the Kubernetes Cluster was more challenging than deploying it in Docker. The main reason is because K8s is evolving every day, and you must adapt to the changes. We have to take in mind that not all the desired applications are developed in K8s so we could not deploy all of them. GitLab has nowadays a PoC in K8s and Jitsi is not offering any support for it, also we have to remark that a GitHub repository[4] with Helm charts is deprecated and it has no longer development. This is due to the Helm 3’s public release and it ended the support on Nov 13, 2020. However we were able to deploy enough applications to cover a company’s needs, we could cover the communication, despite the conferences, the repositories of data, knowledge or information and the easy accessibility. 38 As K8s has integrated ingress, an API object that manages external access to the services in a cluster, also it may provide load balancing, SSL termination and name-based virtual hosting, we do not need to deploy Nginx Proxy Manager. So with the help of Lens, a K8s IDE, it is easy to show the cluster management. In the next figure are represented all the deployments of the cluster. Figure 29: Deployments of the Kubernetes Cluster We know that with the deployment of an application in k8s it will generate the pods, that are the containers running the applications and the services, that expose the application to an externally accessible port. So the next figures represent our pods and services. Figure 30: Pods of the Kubernetes Cluster 39 Figure 31: Services of the Kubernetes Cluster The final figure that represents the accessibility of the applications is the one with the Ingresses of the applications, that provides external access to the cluster. So editing our /etc/host and with a DNS provider we can access to the cluster. Figure 32: Ingresses of the Kubernetes Cluster 5.3 Nested LXC Container Kubernetes Cluster This cluster needed a lot of configurations, as mentioned in the Incidences section, we had a lot of issues to make possible the creation of the cluster. Being the main problem the creation of a zpool in the LXC host. Finally we solve it creating the pool manually using the next command. 40 $ zfs create zpool/lxd - devops Figure 33: Creating a Zpool The results are very similar to the previous section, but this time we have deployed three nodes in the cluster, that are hosting the deployments of each application. Again, with the help of Lens, we can show the cluster specifications. The first figure represents the cluster nodes. Figure 34: Nodes of the Nested LXC Kubernetes Cluster To be able to access the services from outside the cluster, from the host, devops, we needed to edit the /etc/hosts to point to the services inside the cluster, that are exposed, they have an external IP. Inside our master node, in this case node-01, we also need to configure the /etc/hosts to point to the desired service. Figure 35: Ingresses of the Nested LXC Kubernetes Cluster 41 References [1] Docker Inc. Docker Compose Requirements. [Online] Available: https://docs. docker.com/compose/install/, 2020. [Accessed: 15 Nov 2020]. [2] Canonical Ltd. Microk8s Requirements. [Online] Available: https://microk8s.io/ docs, 2020. [Accessed: 15 Nov 2020]. [3] The Artifact Hub Authors. XWiki Helm Chart. [Online] Available: https:// artifacthub.io/packages/helm/keyporttech/xwiki, 2020. [Accessed: Dec 2020]. [4] Helm Authors. Helm Charts. [Online] Available: https://github.com/helm/charts, 2020. [Accessed: Dec 2020]. [5] IEA 2020. Data Centres and Data Transmission Networks. [Online] Available: https: //www.iea.org/reports/data-centres-and-data-transmission-networks, 2020. [Accessed: 27 July 2020]. [6] Christopher Solinas Eddie Antonio Santos, Carson McLean and Abram Hindle. How does docker affect energy consumption? evaluating workloads in and out of docker containers. May 2017. [Online] Available: https://arxiv.org/pdf/1705.01176.pdf [Accessed: Dec 2020]. [7] The Kubernetes Authors. Kubernetes Documentation. [Online] Available: https: //kubernetes.io/docs/home/, 2020. [Accessed: 27 July 2020]. [8] Kubernetes By Example. Kubernetes Examples. [Online] Available: https://docs. docker.com/get-started/overview/, 2020. [Accessed: 27 July 2020]. [9] Docker Inc. Quickstart: Compose and WordPress. [Online] Available: https://docs. docker.com/compose/wordpress/, 2020. [Accessed: Nov 2020]. [10] Jakub Vrána. Adminer. [Online] Available: https://www.adminer.org, 2020. [Accessed: Nov 2020]. [11] GitLab. GitLab. [Online] Available: https://about.gitlab.com, 2020. [Accessed: Nov 2020]. [12] Jitsi. Jitsi. [Online] Available: https://jitsi.org, 2020. [Accessed: Nov 2020]. [13] Mattermost Inc. Mattermos. [Online] Available: https://mattermost.com, 2020. [Accessed: Nov 2020]. [14] Jamie Curnow. OpenLDAP. [Online] Available: https://nginxproxymanager.com, 2020. [Accessed: Nov 2020]. [15] OpenLDAP Fundation. OpenLDAP. [Online] Available: https://www.openldap.org, 2020. [Accessed: Nov 2020]. [16] Nextcloud GmbH. Nextcloud. [Online] Available: https://nextcloud.com, 2020. [Accessed: Nov 2020]. [17] OpenVPN Inc. OpenVPN. [Online] Available: https://openvpn.net, 2020. [Accessed: Nov 2020]. 48 [18] Redmine. Redmine. [Online] Available: https://www.redmine.org, 2020. [Accessed: Nov 2020]. [19] XWiki SAS. XWiki. [Online] Available: https://www.xwiki.org, 2020. [Accessed: Nov 2020]. [20] Canonical Ltd. Microk8s Addons. [Online] Available: https://microk8s.io/docs/ addons, 2020. [Accessed: Dec 2020]. [21] Canonical Ltd. Linux Containers. [Online] Available: https://linuxcontainers. org/, 2020. [Accessed: Dec 2020]. [22] Docker Inc. Why Docker? [Online] Available: https://www.docker.com/ what-docker, 2020. [Accessed: Dec 2020]. [23] Docker Inc. Docker Compose Documentation. [Online] Available: https://docs. docker.com/compose/, 2020. [Accessed: Dec 2020]. [24] Cloud Native Computing Foundation. CRI-O. [Online] Available: https://cri-o. io/, 2020. [Accessed: Dec 2020]. [25] Containerd Authors. Containerd. [Online] Available: https://containerd.io/, 2020. [Accessed: Dec 2020]. [26] VMware inc. Kubernetes Cluster. [Online] Available: https://www.vmware.com/ topics/glossary/content/kubernetes-cluster, 2020. [Accessed: Dec 2020]. [27] The Kubernetes Authors. Kubernetes Commands. [Online] Available: https: //kubernetes.io/docs/reference/generated/kubectl/kubectl-commands, 2020. [Accessed: Dec 2020]. [28] Helm Authors. Using Helm. [Online] Available: https://helm.sh/docs/intro/ using_helm/, 2020. [Accessed: Dec 2020]. 49