Rakesh Jain
Rakesh Jain

@devops_tech

17 Tweets 6 reads Feb 28, 2023
Some kubectl tips and tricks!
A short Thread 👇
[1] Use "kubectl explain" to get detailed information about any Kubernetes resource.
For example, "kubectl explain pod.spec" will give you detailed information about the Pod specification.
[2] Use "kubectl apply" instead of "kubectl create" to update existing resources. "kubectl apply" will make the necessary changes to an existing resource, while "kubectl create" will fail if the resource already exists.
[3] Use "kubectl get" with the "-o wide" option to see more information about your resources.
This will give you additional information such as the IP address, node name, and more.
[4] Use "kubectl edit" to edit resources directly from the command line.
This is especially useful when you need to make small changes to a resource without having to modify the YAML file.
[5] Use "kubectl logs" to view the logs of a specific container within a pod.
For example, "kubectl logs mypod -c mycontainer" will show you the logs for the "mycontainer" container within the "mypod" pod.
[6] Use "kubectl port-forward" to forward a local port to a port on a Kubernetes pod.
This is useful for debugging and accessing resources that are not publicly exposed.
[7] Use "kubectl exec" to execute a command inside a container in a running pod.
For example, "kubectl exec mypod -- ls /" will run the "ls /" command inside the "mypod" pod.
[8] Use "kubectl rollout" to manage rolling updates to your deployments.
This allows you to update your application without downtime by gradually updating the replicas in your deployment.
[9] Use "kubectl top" to view resource usage metrics for your Kubernetes nodes and pods.
This can help you identify resource bottlenecks and optimize your deployments.
[10] Use "kubectl delete" with the "--cascade" option to delete a resource and all of its dependent resources.
This ensures that all related resources are deleted together and avoids leaving orphaned resources in your cluster.
[11] Use "kubectl diff" to see the differences between the current state of a resource and the proposed changes.
This is a useful way to review the changes you're about to make before applying them.
[12] Use "kubectl explain" with the "--recursive" option to see all the fields of a Kubernetes object, including inherited fields.
For example, "kubectl explain --recursive pod.spec" will show you all the fields of the Pod spec, including fields inherited from other objects.
[13] Use "kubectl rollout history" to view the history of changes to your deployments, and "kubectl rollout undo" to roll back to a previous revision.
This can help you recover from failed updates or other issues.
[14] Use "kubectl label" to add labels to resources, and "kubectl get" with the "--selector" option to filter resources by label.
This can help you organize and manage your resources more effectively.
[15] Use "kubectl auth can-i" to check whether a user or group has permissions to perform a specific action in your cluster.
This can help you troubleshoot permissions issues and ensure that your security policies are being enforced.
Retweet the thread if you find it useful. Thanks.

Loading suggestions...