Talks

A brief Introduction of Kubernetes

Ruby Unconf 2019

00:00:02.969 Hello, everyone. I would like to introduce myself by sharing my GitHub profile.
00:00:05.890 I have been working with Ruby since version 1.8.7 and with Rails since version 2.3.2, so I have a fair amount of experience. We are currently in the Dancing Towers at Reeperbahn, which you will see when we go to the party later. I work for a cloud provider called Exxon Game Bihar, which is why I have some experience with Kubernetes.
00:00:28.840 Before I start, I want to make it clear that you can interrupt me anytime if you have questions or suggestions. I tend to talk a bit fast when I'm nervous, so don't hesitate to ask for clarification.
00:01:04.360 Today, I want to start with containers because Kubernetes is primarily about deploying and orchestrating containers. After explaining containers, I will move on to Kubernetes itself. I had intended to do some live programming, but I've encountered some challenges reaching Kubernetes from here, so I will show you some examples we have used in our applications.
00:01:35.590 To start, who here has experience with Docker? Looks like everyone has. Great! I will go through Docker quickly since you are likely familiar with it. Generally, when discussing Docker, people differentiate between virtual machines and containers. The main distinction is that when you run a Docker container, you do not have a separate kernel for each instance. Unlike virtual machines, which encapsulate their own operating systems, containers share the host OS while encapsulating binaries and libraries.
00:02:04.080 When you delve deeper into Kubernetes, it can get complicated. Often, you run Kubernetes in the cloud with KVM, which involves virtual machines and containers. I will return to this topic shortly. For now, let's look at a standard Docker file since many of you have experience with it. I won’t cover it in-depth, but one key point is that after building a container, you can encapsulate it and use it in your pipelines for testing.
00:02:49.760 Automated tests often help ensure that the containerized increments work correctly. There are various tests you can run, such as using NPM audit or Bundle audit to check your container's security. These should be recurrent tasks, but the critical tests must always function as expected.
00:03:19.600 Now let’s talk about Kubernetes. Once you have your container, running an application using just one container on one VM does not provide high availability or scalability. For that purpose, we introduce Kubernetes as an orchestration tool to manage multiple benefits, including networking and deployment.
00:03:43.560 Kubernetes is an open-source project started by Google and has become the de-facto standard for container configuration and automation. You can liken it to OpenStack, which is for VMs, whereas Kubernetes is designed for containers. It's an excellent tool for bringing your containerized applications into production.
00:04:02.880 Kubernetes is highly scalable. For example, if you have a master node and two worker nodes and require more capacity, you can quickly add another worker node. Kubernetes also allows you to scale applications up or down with minimal configuration changes. It manages the number of containers based on your specified health checks.
00:04:35.410 As you may know, there are many operators working directly with Kubernetes, which means its development is continually advancing. If you're interested in experimenting with Kubernetes, I recommend checking out a project called K3s. K3s is a lightweight version of Kubernetes that is easy to install and ideal for experimentation.
00:04:51.470 Next, I want to look at Kubernetes architecture. Key components include etcd, which is a key-value store that holds the entire state of Kubernetes, and network solutions like Calico. Understanding these components can help you appreciate Kubernetes' capabilities.
00:05:11.530 Kubernetes consists of several components, with the smallest unit being the pod. A pod is the minimum requirement to run a containerized application. In many cases, it might just contain one container, which runs your application. However, there are scenarios where you need additional processes within the same pod.
00:05:25.790 For example, if you want an NGINX server to serve static assets in parallel with an application container, you can define both in the same pod. Another instance might be an application that requires a logging agent; you could declare the application and the logging agent in the same pod to facilitate log handling.
00:05:51.180 The next important unit is the ReplicaSet. You define a ReplicaSet to maintain a specified number of pod replicas. For instance, if you want three replicas of a specific pod running, Kubernetes will ensure that the desired number is maintained, restarting any containers that crash.
00:06:17.600 Continuing with deployment, the Deployment configuration defines the desired state, including which pods and ReplicaSets to maintain. It allows you to specify the number of containers and provides elasticity. Additionally, you can define environment variables and other configurations through ConfigMaps.
00:06:40.680 The Service declaration describes which pods to expose. This often leads to confusion among newcomers since there is a distinction between Deployments for running pods and Services for routing traffic to those pods.
00:07:05.990 Services offer ways to expose applications running inside Kubernetes to the outside world. For example, if you are using a distributed database like CockroachDB, you would define a service to manage that database while providing a single point of access. Services can also handle load balancing and failover.
00:07:35.170 An Ingress resource acts as a load balancer that allows you to define rules for routing traffic to different services, based on the domain name in the request.
00:07:59.320 Additionally, the Helm package manager simplifies deploying applications in Kubernetes. It allows you to create templates for your configurations, making it easier to reuse and define different environments.
00:08:20.610 With Kubernetes, you can automate tasks using cron jobs. For instance, if you decide to run a database within Kubernetes, you can schedule regular backups through a cron job that runs a specific container on a defined schedule.
00:08:45.740 Kubernetes supports namespaces, which enable you to organize different projects and manage service accounts that have access to specific namespaces.
00:09:05.780 I had planned to do some live coding today, but I may have some firewall restrictions that prevent me from accessing Kubernetes directly. If anyone is interested, I can conduct a workshop tomorrow to explore Kubernetes further.
00:09:32.690 Now, let’s take a moment to discuss Helm templates. The first thing you need to define in a Helm template is the deployment type, specifying the number of replicas and the container details.
00:09:57.970 For instance, in our deployment, we specify container images, environment variables, config maps, and other necessary information. This allows us to manage how our app is configured and ensure everything runs smoothly.
00:10:45.260 I am receiving questions, and it’s great to see engagement. Kubernetes offers many advantages over simpler technologies like Docker Compose. While Docker Compose allows you to define how containers interact on a single machine, Kubernetes provides orchestration across multiple nodes.
00:11:11.640 Kubernetes includes health checks and various automation features that aren't present in Docker Compose. These features include load balancing, service discovery, and automated scaling.
00:11:38.330 Kubernetes allows for simplified deployment and management of applications, making it easier to manage large-scale applications with numerous services.
00:12:05.200 While using ORM with Kubernetes offers complexities, the flexibility it provides for managing stateful applications is significant.
00:12:28.060 For example, when dealing with databases in Kubernetes, you can define persistent volumes for your database, allowing easier management of storage and data persistence across deployments.
00:12:55.544 Kubernetes also allows you to create cron jobs for tasks that need to run on a schedule, increasing the automation of your workflows.
00:13:18.265 Using Kubernetes namespaces, you can manage resources more effectively and ensure that service accounts have the appropriate access rights.
00:13:42.191 To summarize, Kubernetes is a powerful tool that greatly enhances your ability to deploy and manage containerized applications effectively.
00:14:07.670 Thank you all for listening. I hope you found this introduction to Kubernetes helpful, and I look forward to your questions or feedback.