This tutorial aims to provide a comprehensive guide on managing Kubernetes Pods, Services, and Deployments.
By the end of this tutorial, you will be able to:
Basic knowledge of Kubernetes and its architecture is required. Familiarity with YAML and command-line interface is desirable.
# Create a Pod
kubectl run my-pod --image=nginx
This command creates a Pod named "my-pod" running the Nginx image.
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
This YAML file creates a Deployment that spins up three replicas of Pods running the Nginx 1.14.2 image.
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 9376
This Service "nginx-service" exposes the application running on the Pods with the label "app=nginx" on port 80.
In this tutorial, you learned how to manage Kubernetes Pods, Services, and Deployments. Consider exploring other Kubernetes objects like StatefulSets, DaemonSets, and Jobs for more advanced use cases.
Create a deployment with two replicas running the hello-world
image.
Expose the hello-world
deployment as a service on port 8080.
Scale up the hello-world
deployment to five replicas.
Refer to the Kubernetes documentation for syntax and further practice. Remember, practice is key when learning new skills.