Kubectl proxy and curl
Author: Fabrice JAMMES (LinkedIn).
Objective
Learn how to use kubectl proxy and curl to list services in a specified Kubernetes namespace.
Prerequisites
- A running Kubernetes cluster
kubectlinstalled and configuredcurlinstalled
Steps
Step 1: Start kubectl proxy
Run the following command to start the kubectl proxy:
kubectl proxy &Note
In case of port conflict use the --portoption
This command runs kubectl proxy in the background, allowing API requests to be sent to the Kubernetes API server via localhost.
Step 2: List Services in a Namespace using curl
To list the services in a given namespace, use the following curl command:
Expected Output
You should see a JSON output listing the services running in the specified namespace, including their metadata, specifications, and statuses.
Cleanup
If you want to stop the kubectl proxy, find the process ID and terminate it:
ps aux | grep kubectl
kill <PID>Alternatively, you can use:
pkill -f kubectlConclusion
You have successfully queried Kubernetes services using kubectl proxy and curl. This method allows direct interaction with the Kubernetes API for retrieving resource information.