This is What You Need to Know About Kubernetes YAML, Pods, Deployments, and ReplicaSets (1/3)
In this step by a step tutorial, we will explore and discuss different options to deploy applications on Kubernetes clusters, and we will focus on the following points: The basics of YAML, creating Pods in Kubernetes, deploying applications using Pods and deploying applications using Deployments.
Before proceeding, make sure that your environment satisfies these requirements. Start by installing Docker and Kubectl in your machine. You will also need a K8s cluster; you can use Minikube for this purpose.
Introduction to YAML
Kubernetes is a tool that can be used for automating deployment, scaling, and management of containerized applications. Interacting with Kubernetes can be used via Restful API requests to the Kubernetes API server. The Kubernetes API server is responsible for accepting the requests for performing actions on the Kubernetes clusters. These actions can be performed to create, read, update, or delete resources from the Kubernetes cluster.
To interact with the Kubernetes API server, you need to know the URL or the API server, and you have to build your web request with JSON (The body of the request that represents the Kubernetes resources). Managing Kubernetes resources in JSON is tricky due to readability issues. Luckily the kubectl command allows us to define the Kubernetes in a more readable and easy to write format, which is YAML, and the kubectl will take care of translating the resource definitions to JSON format and send the request to the API server.
YAML (Yet Another Markup Language) is a human-readable data serialization language. YAML is widely used for defining and storing configuration and data. YAML allows us to store complex data and configurations such as Lists, Maps, and more Objects. For instance, on the one hand, YAML allows us to define collections of items such as the list of top movies, and on the other hand, it allows us to define a nested mapping like the list of actors in each movie.
The below snippet is showing an example of an invoice in the YAML format.
--- receipt: Liddo Invoice date: 2020-09-24 customer: first_name: Jan family_name: Marria items: - part_no: B4896 descriptin: Cable price: 1.47 quantity: 4 - part_no: RH628 descrip: CD/DVD size: 8 price: 133.7 quantity: 1 bill-to: &address street: | 345 Tornado Alley Suite 40 city: East Centerville state: KS ship-to: *address
As you can see in the above snippet YAML is an easy-to-read format, and it also allows reusing the data defined instead of duplicating it over and over. For instance, in the above file, we defined the customer address only once and reused it for the ship-to configurations.
As said before, the Kubectl tool allows us to define the Kubernetes resources in the YAML format. It will take care of managing the communications with the Kubernetes API server. This feature has a big advantage because it is much easier to write and read the Kubernetes resource definitions in the YAML format.
Kubernetes Resources: Pods, Deployments, and ReplicaSets
Kubernetes offer a wide range of resources that can be created and managed by the cluster, such as Secrets, Configmaps, services, deployments, and many others. The supported resources cover and support several areas that are related to hosting and securing applications running on the Kubernetes cluster. For Instance, a Pod resource is used to represent a running instance of given applications, while a namespace resource is used to isolate a group of resources from other resources that belong to different namespaces.
To view the complete list of the resources supported by Kubernetes, you can use the below command, as shown in the screenshot.
From the above screenshot, it is clear that each of the supported resources has the following attributes: resource name, API group, kind, and whether the resource is scoped to a specific namespace or is available on the cluster level. These attributes are very important for defining the resources of YAML files, especially the Kind and the API group.
Each of the supported resources can be managed by creating a YAML file representing the status of the resource and then using the kubectl command to instruct Kubernetes to create the same resource.
In part 2 of "This is What You Need to Know About Kubernetes YAML, Pods, Deployments, and ReplicaSets", we will focus on the general structure of the Kubernetes YAML files and the possible ways to create a Pod resource.
Share this story with your friends
4 hours ago
23 hours ago
1 week, 6 days ago
1 month ago