CKA Tips
Pod
Create an NGINX pod
kubectl run nginx --image=nginx
# Generate Pod manifest YAML file (-o yaml). Don't create it (--dry-run)
kubectl run nginx --image=nginx --dry-run=client -o yaml
Deployment
Create a Deployment
kubectl create deployment --image=nginx nginx
# Generate Deployment YAML file (-o yaml). Don't create it (--dry-run)
kubectl create deployment --image=nginx nginx --dry-run=client -o yaml
# Generate Deployment with 4 Replicas
kubectl create deployment nginx --image=nginx --replicas=4
# You can also scale a Deployment using the kubectl scale command.
kubectl scale deployment nginx --replicas=4
# Another way to do this is to save the YAML definition to a file and modify
kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > nginx-deployment.yaml
Service
Create a Service named redis-service of type ClusterIP to expose the redis pod on port 6379
# Expose will automatically use the pod labels.
kubectl expose pod redis --port=6379 --name redis-service --dry-run=client -o yaml
# Creating a service this way it will not use the labels. Use it to create the manifest and add the necessary labels.
kubectl create service clusterip redis --tcp=6379:6379 --dry-run=client -o yaml