Introduction to Kubernetes YAML Parameters and Quick Generation of YAML Files
This article explains the basics of YAML syntax, demonstrates how to generate Kubernetes resource files such as an Nginx deployment using kubectl without applying them, and compares the differences between kubectl create and kubectl apply for interview preparation.
1. Introduction – An overview of Kubernetes resource file YAML parameters.
2. What is YAML – YAML is a markup language similar to XML and JSON that focuses on data representation. For example, SpringBoot’s application.yml is a YAML file.
3. Syntax Rules
Hierarchy is expressed by indentation (spaces only, no tabs).
Typical indentation is two spaces.
YAML is case‑sensitive.
A colon (:) or dash (-) must be followed by a space.
Multiple documents in one file are separated by --- .
Comments start with # .
4. Quickly Generate a YAML File Without Deploying
Run the following command to create an Nginx deployment manifest and save it to nginx1.20.yaml without starting the resource:
kubectl create deployment haha-nginx --image=nginx:1.20.0 -o yaml --dry-run=client > nginx1.20.yaml
Viewing the generated file:
cat nginx1.20.yaml
The resulting YAML (excerpt) is:
apiVersion: apps/v1 # API version
kind: Deployment # object type
metadata:
name: haha-nginx
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: haha-nginx
template:
metadata:
labels:
app: haha-nginx
spec:
containers:
- name: nginx
image: nginx:1.20.0
resources: {}5. Interview Question
Difference between kubectl create and kubectl apply :
kubectl create creates a resource the first time; subsequent runs fail because the resource name already exists in the namespace.
kubectl apply also creates the resource on the first run, but on subsequent runs it updates or patches the existing resource based on the manifest, even if the manifest has not changed.
If this article helped you, please like, view, and share—it encourages me to continue creating high‑quality content. Thank you! 🙏🏻
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.