Learn KUBERNETES-YAML with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Simple Kubernetes Deployment
# kubernetes/demo-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
A simple Kubernetes Deployment running an Nginx container.
2
Simple Kubernetes Service
# kubernetes/demo-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: default
spec:
type: ClusterIP
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
A simple Kubernetes Service exposing the Nginx Deployment.