Step-by-Step Guide to Kubernetes Config Files
To create Kubernetes configuration files for a Deployment and Services using the provided YAML snippets (nginx-deployment.yaml, nginx-service.yaml) and to apply them to your Kubernetes cluster, follow these steps :
1. Create Configuration Files
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 8080
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8080
Save each of these YAML files in your local directory.
2. Apply Configurations to Kubernetes Cluster
Using Commands
Assuming you have kubectl configured to point to your Kubernetes cluster, follow these steps:
Apply Deployment Configuration:
kubectl apply -f nginx-deployment.yaml
- This command will create or update the Deployment named
nginx-deployment
based on the YAML file provided.
- This command will create or update the Deployment named
Apply nginx-service Configuration:
kubectl apply -f nginx-service.yaml
3. Verify Deployment and Services
After applying the configurations, you can verify their status and details using commands:
Check Deployments, Services and pods:
kubectl get deployments kubectl get services kubectl get pods // or for all kubectl get all | grep nginx
Summary
By following these steps, you can create Kubernetes configuration files , apply them to your Kubernetes cluster using kubectl apply and verify the deployment and services. This process ensures that your applications are deployed and accessible within your Kubernetes environment according to the specified configurations.