How to view a YAML file with kubectl?

You can specify the filename to view when using the ‘kubectl get’ command with the -f flag to view a YAML file. Here are the more detailed steps:

Open the terminal and make sure that kubectl is installed, and that the connection to the Kubernetes cluster is properly configured.

Navigate to the directory containing the YAML file you want to view.

   cd /path/to/yaml/files

Run the following command to view the contents of the YAML file:

   kubectl get -f <filename.yaml> -o yaml

Please replace with the actual name of the file you want to view.

The output will be displayed in YAML format on the terminal, showing detailed information about Kubernetes objects, such as Pods, Deployments, Services, and more.

Note: This method is suitable for existing YAML files in the Kubernetes cluster. If you want to create a new Kubernetes object, use the kubectl apply command instead of the kubectl get command.

bannerAds