Member-only story
23 Advanced kubectl commands
Collection of useful kubectl commands
Published in
7 min readJun 20, 2019

Updated: Dec 21, 2020
I’ve personally used these commands to debug in production. I also used GUI methods like k9s and lenses.io.
0. Impersonate a user and group
kubectl get pods --as-group="somecompany:somecompany-teamname" --as="test"
1. Explain a resource
❯ kubectl explain hpaKIND: HorizontalPodAutoscaler
VERSION: autoscaling/v1DESCRIPTION:
configuration of a horizontal pod autoscaler.FIELDS:
apiVersion <string>
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resourceskind <string>
Kind is a string value representing the REST resource this object
represents. Servers may infer this from the endpoint the client submits
requests to. Cannot be updated. In CamelCase. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kindsmetadata <Object>
Standard object metadata. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadataspec <Object>
behaviour of autoscaler. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.status <Object>
current information about the autoscaler.kubectl explain svc
2. Get nodes region and zone
❯ kubectl get nodes --label-columns failure-domain.beta.kubernetes.io/region,failure-domain.beta.kubernetes.io/zoneNAME STATUS ROLES AGE VERSION REGION ZONE
ip-11-0-109-70.eu-west-1.compute.internal Ready <none> 5d21h v1.16.15-eks-ad4801 eu-west-1 eu-west-1b…