Kubernetes

How Do I Export YAML from Deployed Kubernetes Services?

A Kubernetes deployment instructs Kubernetes about how to generate or change instances of pods that contain containerized applications. Deployments can grow the number of replica pods, allow for controlled release of updated code, or revert to a previous deployment edition if needed. Because the Kubernetes deployment controller constantly monitors the status of pods and nodes, it can swap a failing pod or bypass down nodes, ensuring that vital applications continue to run. Deployments can be upgraded by implementing adjustments to the Pod templates spec inside the deployment, enabling an update rollout to occur instantly. Operational pods will stop taking requests if the Pod template is changed, allowing them to be scaled back till all pods can be canceled. The revised pod design will be used to construct new pods once they’ve been destroyed.

If you are working with many different types of software, especially Kubernetes, it’s impossible to avoid YAML. YAML (Yet Another Markup Language) is a text-based standard for expressing configuration settings that is human-readable. Furthermore, because YAML is a superset of JSON, any acceptable JSON file also qualifies as a proper YAML file. So, if you understand JSON and will only ever create your YAML, so, in this tutorial, we will explain to you a method to export YAML from deployed Kubernetes service.

Pre- Requisites

So to export YAML from deployed Kubernetes services, you must have Ubuntu 20.04 installed on your system. You can utilize any other Linux distribution as well. Kubernetes clusters can run on both physical and virtual machines. You could use Minikube to get acquainted with Kubernetes development. To run Kubernetes on Ubuntu 20.05 system, make sure you have installed a minikube cluster.

Method to export YAML from deployed services of Kubernetes

Now we are ready to learn the basic method to export YAML from deployed Kubernetes services. So, open the command line terminal of Ubuntu 20.04 by looking into the sets of available applications or using the “Ctrl+Alt+T” shortcut key.

Step 1: Start minikube Cluster

Once the command line terminal of the Ubuntu 20.04 system is opened, the first and most important step is to start a minikube cluster. To get started with minikube, you have to execute the below-appended command in the terminal and tap the “Enter” key.

$ minikube start

During execution, you can view the version of minikube installed on your system and the available version. If needed, you can update it as well. The process to start a minikube will take a few minutes. During this process, it is requested not to quit the terminal window. Otherwise, it will stop.

Step 2: View information regarding the current cluster

Now, it is time to view the complete information of your current cluster. So, write the following listed kubectl command in the terminal window.

$ kubectl get all

After successfully executing this command, you can verify the name, type Cluster IP, External IP(if any), relevant Ports, and age of your current cluster.

Step 3: Creating Single YAML for all services

Now, If you want to build a single YAML file for all of the service resources in your Kubernetes cluster, you can use the below listed kubectl command in your terminal.

$ kubectl get service --all-namespaces -o yaml  > all-service.yaml

The execution of this command will create the YAML  and save it in the all-service.yaml that is also mentioned in the command.

Step 4: Creating Single YAML for all deployed services

Now you can use the preceding kubectl command in the terminal to create a single YAML for all deployed resources within the Kubernetes cluster.

$ kubectl get deploy --all-namespaces -o yaml  > all-deployment.yaml

The execution of this command will result in the creation of YAML and saving it into all-deployment.yaml. Now, you can see that we have successfully exported YAML; from the deployed Kubernetes services.

Conclusion

In this guide, we have covered the basic concept of deploying Kubernetes services and the YAML guidelines. Also, we have explained the method to export YAML from deployed Kubernetes services. The whole article is very easy to implement and understand. Now I believe that after looking deep in this guide, you can conveniently export YAML from the deployed Kubernetes services.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content