Kubernetes YAML file, which I copied from PDF file. It should be nice, if I could format the file in order to have the correct indentation of the k8s file
What I have now:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
What would I like to have
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
Additional information: from my current vscode (1.73.1) I have already installed both the following extensions
Name: YAML
Id: redhat.vscode-yaml
Description: YAML Language Support by Red Hat, with built-in Kubernetes syntax support
Version: 1.10.1
Publisher: Red Hat
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml
and
Name: Kubernetes YAML Formatter
Id: kennylong.kubernetes-yaml-formatter
Description: A better YAML formatter for DevOps like Kubernetes, Ansible, CI/CD, etc.
Version: 1.1.0
Publisher: kennylong
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=kennylong.kubernetes-yaml-formatter
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
I don’t think that there is something out of the box that will work for more complex Kubernetes YAML files.
The closes that I’ve seen so far is the YAML extension by Red Hat:
https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml
Once you install it, you can right-click on the YAML file’s content and select “Format Document” from the context menu.
Unfortunately, it does not seem to work for all cases.
What I personally do is to use the
kubeval
tool to validate my YAML files:https://www.kubeval.com/
Hope that this helps!
Best,
Bobby