Creation of a Kubernetes Infrastructure
Total Page:16
File Type:pdf, Size:1020Kb
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 wayto 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 apli- cacions 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 virtu- alització 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 de- splegar 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 Statement of purpose .............................. 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 Work Packages ............................. 15 1.4.2 Milestones ................................ 16 1.4.3 Gantt Diagram ............................. 17 1.5 Deviations from the initial plan and incidences. ............... 17 1.5.1 Plan changes .............................. 17 1.5.2 Incidences ................................ 17 2 State of the art of the technology used or applied in this thesis: 19 2.1 Container Deployment ............................. 19 2.2 Docker ...................................... 20 2.2.1 Docker Compose ............................ 20 2.3 Kubernetes ................................... 21 2.3.1 Kubectl ................................. 21 2.3.2 Helm ................................... 21 2.3.3 Microk8s ................................ 22 2.4 LXD Containers ................................ 23 3 Methodology: 24 3.1 Communication ................................. 24 3.2 Software ..................................... 24 3.2.1 Git .................................... 24 3.2.2 Docker Compose ............................ 25 3.2.3 Microk8s ................................ 25 3.2.4 LXD ................................... 25 3.3 Documentation ................................. 25 4 Project Development: 26 4.1 Selected Applications .............................. 26 4.2 Desired Cluster ................................. 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 Kubernetes Cluster ............................... 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 Kubernetes Cluster ............................... 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 Container Evolution .............................. 19 3 Useful Docker Compose Commands ...................... 20 4 Useful Kubectl Commands ........................... 21 5 Useful Helm Commands ............................ 22 6 Useful Microk8s Commands .......................... 22 7 LXC Commands: Useful Commands ..................... 23 8 Desired Cluster ................................. 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 Creation of a Zpool ............................... 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 State of