Cloud Native 7 min read

Common Kubernetes Commands for Creating, Managing, and Monitoring Resources

This guide presents essential kubectl commands for creating and managing Deployments, Pods, Services, and Ingresses, checking cluster and node status, running container applications, updating images and resource limits, and handling log collection and monitoring in a Kubernetes environment.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Common Kubernetes Commands for Creating, Managing, and Monitoring Resources

1. Create and manage resources

Create a Deployment: kubectl create deployment hello-world --image=gcr.io/google-samples/hello-app:1.0 . List Deployments: kubectl get deployments . Update image: kubectl set image deployment/hello-world hello-world=gcr.io/google-samples/hello-app:v2 . Roll back: kubectl rollout undo deployment/hello-world --to-revision=1 . Delete Deployment: kubectl delete deployment hello-world . View logs: kubectl logs -f deployment/hello-world .

Manage Pods: create with kubectl run nginx --replicas=3 --image=nginx , list with kubectl get pods , delete with kubectl delete pod nginx , view logs with kubectl logs -f nginx .

Manage Services: expose a Deployment via kubectl expose deployment/nginx --port=80 --target-port=80 --type=NodePort , describe with kubectl describe service nginx , patch with kubectl patch service/nginx -p '{"spec": {"ports":[{"name":"http","port":80,"targetPort":80}]}}' , delete with kubectl delete service nginx .

Manage Ingresses: apply rule kubectl apply -f examples/guestbook/redis-ingress.yaml , describe with kubectl describe ingress nginx , replace with kubectl replace --force=true -f examples/guestbook/redis-ingress.yaml , delete with kubectl delete ingress nginx .

2. View Kubernetes cluster status

Cluster info: kubectl cluster-info . Nodes: kubectl get nodes and detailed info kubectl describe node . Node IPs: kubectl get nodes -o wide . Node resource usage: kubectl top node . Pods across namespaces: kubectl get pods -A --all-namespaces . Services and Deployments: kubectl get services,deployments . Resource quotas: kubectl describe quota . Individual Pod status and logs: kubectl get pods , kubectl describe pod , kubectl logs .

3. Run container applications

Run a new container: kubectl run nginx --replicas=3 --image=nginx . Update image: kubectl set image deployment/nginx new-image:tag . View container logs: kubectl logs -f nginx . Scale controllers: kubectl scale rc/rc-name --replicas=n . Check pod health: kubectl describe pod/pod-name . Perform rolling updates: kubectl rollout status deploy/deployment-name . List events: kubectl get events .

Service monitoring: expose external address with minikube service service-name , view status with kubectl get services , change type via kubectl patch svc nginx -p '{"spec":{"type":"LoadBalancer"}}' , reset with kubectl rolling-update service-name -c new-config .

Ingress routing: create rule kubectl apply -f path/to/rule.yaml , replace with kubectl replace -f path/to/rule.yaml , list with kubectl get ingresses , delete with kubectl delete ingresses ingress-name .

4. Update application images and resource limits

Rollback to previous revision: kubectl rollout undo deployment/nginx-deployment --to-revision=1 . Set new image: kubectl set image deployment/nginx-deployment nginx=new_image . Edit deployment to change CPU/memory limits: kubectl edit deployment/nginx-deployment .

5. Log management and monitoring

Fetch pod logs: kubectl logs deployment/nginx-pod or follow with kubectl logs -f deployment/nginx-pod . Deploy Fluentd for log collection: kubectl apply -f https://raw.githubusercontent.com/kubernetes/fluentd-elasticsearch-stack/master/stackdriver-gcp.yaml . Verify Fluentd daemonset: kubectl describe daemonset fluentd-gcp-v2.0.18-logging . View collected logs: kubectl logs $(kubectl get pods -l app=fluentd-gcp -o jsonpath='{.items[0].metadata.name}') .

cloud nativeoperationsKubernetesDevOpsContainer Orchestrationkubectl
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.