Using kubectl run to get things up and running quickly using Kubernetes is a breeze. However, a YAML file is required for further functionality and a thorough technique.
Any valid JSON file is considered a valid YAML file because YAML is a superset of JSON. On the one hand, you are fine to go if you know JSON and will only ever write your own YAML (rather than reading others). That is not a likely situation. Even if you are merely searching the web for examples, they are almost certainly written in (non-JSON) YAML; therefore, we should get used to it. Nevertheless, there may be occasions when the JSON format is more beneficial, so knowing that it is available is useful.
When you create a Kubernetes object, you must include both the object spec and some basic information about it (such as a name). That information must be supplied in the request body as JSON when using the Kubernetes API to create the object (directly or via kubectl). A .yaml files are commonly used to supply information to kubectl, and the data is transformed to JSON when using kubectl to perform an API request.
It is impossible to avoid YAML while working with a variety of technologies, especially Kubernetes. YAML is a human-readable text-based standard for defining configuration settings. This article will show you how to export YAML from a deployed Kubernetes service, presuming you understand JSON and will only ever write YAML.
Before You Start
You must have Ubuntu 20.04 installed on your system to run the commands, and any other Linux distribution will suffice. Physical and virtual machines can run Kubernetes clusters, and Minikube is an excellent method to learn Kubernetes programming. Before launching Kubernetes on Ubuntu 20.04, make sure you have a minikube cluster installed.
We are now ready to learn how to export YAML from Kubernetes services that have been deployed. So, scroll through the programs or press the shortcut key “Ctrl+Alt+T” to get to the Ubuntu 20.04 command-line terminal.
1. Start a Minikube Cluster Setup
The minikube cluster must be started initially. The first and most crucial step after launching the Ubuntu 20.04 command-line interface is to create a minikube cluster. To use minikube, you must open a terminal, type the minikube start command, and hit the “Enter” key. You may see both the version of minikube that is installed on your PC and the version that is accessible at the time of execution. If necessary, you can alter it. A minikube can be started in only a few minutes. It is endorsed that you do not close the terminal window while performing this procedure, and it will come to a standstill if this does not happen.
2. Get Information About the Current Cluster
It is time to take a closer look at the specifics of your current cluster. Type the kubectl command listed below in the terminal window.
3. Generate YAML File
Using the kubectl command, you may form a YAML file in your Kubernetes cluster. This command successfully creates YAML and saves it in the all-service.yaml file, which is also referenced in the command.
4. For all deployed services, get YAML
You may now use the kubectl command in the console to generate a single YAML for all deployed resources in the Kubernetes cluster using the previous kubectl command. This command generates YAML and saves it in a file called all-deployment.yaml. As you can see, we were able to extract YAML from the Kubernetes services that were launched.
In this editorial, we have covered the fundamentals of deploying Kubernetes services and the YAML standards. We have also given a comprehensive explanation of how to export YAML, and the entire information is straightforward to understand and use. We are confident that after thoroughly reading this post, you will be able to simply export YAML from your Kubernetes services.