kubernetes API server provides RESTful endpoints that allow kubectl to make HTTP requests to view and manage Kubernetes resources and their objects.
The URI of the endpoints can be constructed using the name of a resource (this will return the info of its objects), and can be narrowed by using the name of an object of the resource.
The URI can be further detailed if the object regroup other resources and hence the URI can be expanded by adding the name of the resource and any of its objects.
For example, the following endpoint returns information about all Pods in the default namespace:
http://localhost:8001/api/v1/namespaces/default/pods/
If you access
http://localhost:8001/ you should see all the endpoints accessible at the ROOT level.
To see the version of the API server, oen
http://localhost:8001/version
You can use the "
kubectl get <resource-name>" command to view information about the objects of a kubernetes resource.
You can specify an object name "
kubectl get <resource-name> <object-name>" to view information about that object.
By default you can view resources of the current namespace configured for the kubectl config
(the "
default" namespace is used if none is configured).
To confugure another namespace for the current context you can use the commande:
"
kubectl config set-context my-context --namespace=my-namespace"
You can also override the namespace by using the "
--namespace" flag ("
-n"):
"
kubectl get <resource-name> -n another-namespace"
You can also use the "
--all-namespaces" flag to view information about resources from all the namespaces of the cluster:
"
kubectl get <resource-name> --all-namespaces"
To see information about the Pods resource:
You can use the "
-o wide" flag to get more information about the resource.
You can also remove the headers from the output by adding the "
--no-headers" flag.
This can be useful if you want to do custom actions on the output.
By default, kubectl doesn't show the full response of the API server.
You can print the full response in either YAML or JSON formats by using the "
-o yaml" or "
-o json" flags.
You get a similar response by targeting directly the API server endpoint:
http://localhost:8001/api/v1/namespaces/default/pods/
You can get detail of an abject by specifying its name after the resource.
kubectl: "
kubectl get Pods dnsutils -o json"
API Server endpoint:
http://localhost:8001/api/v1/namespaces/default/pods/dnsutils
You can use the "
-o jsonpath" flag that allows you to use the JSONPath expressions to filter on specific fields in the JSON object
https://kubernetes.io/docs/reference/kubectl/jsonpath/
Another way to get details about an object is to use the "
kubectl describe" command:
kubectl describe <resource-name> <object-name>
You can get information about a specific Kubernetes resource:
kubectl explain <resource-name>