📄 YAML
Almost everything in Kubernetes is described in YAML files: you write what you want ("2 pods with this image") and the cluster makes it happen. This page shows how to read, generate, validate and apply these files.
YAML files are applied with kubectl. The Nuvion Panel does not have a YAML editor for cluster resources.
🚀 Before you start
- Have cluster access configured (see Cluster Access).
📖 The structure of every Kubernetes YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: exemplo
spec:
replicas: 1
| Field | What it is |
|---|---|
apiVersion | The resource's API version |
kind | The type (Pod, Deployment, Service...) |
metadata | Name, labels (labels) and namespace |
spec | What you want to exist |
📏 YAML rules
- Use 2 spaces to indent. Never use Tab.
- Lists start with
-(dash and space). - Text with
:or special characters goes in quotes. - Several resources in the same file are separated by
---.
🚀 1. See the YAML of an existing resource
kubectl get deployment NAME -o yaml
The output has extra fields, filled in by the cluster (such as status). It is for reference.
🚀 2. Generate a ready-made template
Instead of writing from scratch, let kubectl generate it and save it to a file:
kubectl create deployment meu-app --image=nginx:1.27 --replicas=2 --dry-run=client -o yaml > meu-app.yaml
--dry-run=client creates nothing in the cluster, it only generates the text.
🚀 3. Look up a field's documentation
kubectl explain deployment.spec.replicas
kubectl explain deployment.spec.strategy
This command explains each field, without leaving the terminal.
🚀 4. Validate before applying
kubectl apply -f meu-app.yaml --dry-run=server
kubectl diff -f meu-app.yaml
The first asks the cluster to validate the file without creating anything. The second shows what will change compared to what already exists.
🚀 5. Apply
kubectl apply -f meu-app.yaml
apply creates the resource if it does not exist and updates it if it does. Use the same
command to create and to change.
🚀 6. Change an existing resource
There are two ways:
| Way | Command | When to use |
|---|---|---|
| Edit the file | Change meu-app.yaml and run kubectl apply -f meu-app.yaml | Recommended: the file remains the source of truth |
| Edit directly in the cluster | kubectl edit deployment meu-app | Quick adjustments and testing |
🚀 7. Delete using the file
kubectl delete -f meu-app.yaml
✅ How to know it worked
kubectl get deployment meu-app
The Deployment appears with READY 2/2.
🔒 Best practices
- Store YAML files in a repository (Git), without passwords. For sensitive data, use Secrets.
- Run
kubectl diffbefore applying in production. - Use one file per application, with clear names.
❗ Common problems
| Message | Cause | Solution |
|---|---|---|
error converting YAML to JSON | Indentation error or Tab in the file | Review the spaces (2 per level) |
unknown field "..." | Field misspelled or in the wrong place | Use kubectl explain to see the correct name |
no matches for kind | Incorrect apiVersion or kind | Check with kubectl api-resources |
selector does not match template labels | matchLabels differs from labels | Use the same label in both |
field is immutable | Field that cannot be changed after creation | Delete and create again |
🧹 Cleanup
kubectl delete -f meu-app.yaml
rm meu-app.yaml
🧠 Questions?
Talk to our SaveinCloud technical support team!