Use an HTTP Proxy to Access the Kubernetes API

This page shows how to use an HTTP proxy to access the Kubernetes API.

Before you begin

You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using minikube or you can use one of these Kubernetes playgrounds:

To check the version, enter kubectl version.

If you do not already have an application running in your cluster, start a Hello world application by entering this command:

  1. kubectl create deployment node-hello --image=gcr.io/google-samples/node-hello:1.0 --port=8080

Using kubectl to start a proxy server

This command starts a proxy to the Kubernetes API server:

  1. kubectl proxy --port=8080

Exploring the Kubernetes API

When the proxy server is running, you can explore the API using curl, wget, or a browser.

Get the API versions:

  1. curl http://localhost:8080/api/

The output should look similar to this:

  1. {
  2. "kind": "APIVersions",
  3. "versions": [
  4. "v1"
  5. ],
  6. "serverAddressByClientCIDRs": [
  7. {
  8. "clientCIDR": "0.0.0.0/0",
  9. "serverAddress": "10.0.2.15:8443"
  10. }
  11. ]
  12. }

Get a list of pods:

  1. curl http://localhost:8080/api/v1/namespaces/default/pods

The output should look similar to this:

  1. {
  2. "kind": "PodList",
  3. "apiVersion": "v1",
  4. "metadata": {
  5. "resourceVersion": "33074"
  6. },
  7. "items": [
  8. {
  9. "metadata": {
  10. "name": "kubernetes-bootcamp-2321272333-ix8pt",
  11. "generateName": "kubernetes-bootcamp-2321272333-",
  12. "namespace": "default",
  13. "uid": "ba21457c-6b1d-11e6-85f7-1ef9f1dab92b",
  14. "resourceVersion": "33003",
  15. "creationTimestamp": "2016-08-25T23:43:30Z",
  16. "labels": {
  17. "pod-template-hash": "2321272333",
  18. "run": "kubernetes-bootcamp"
  19. },
  20. ...
  21. }

What’s next

Learn more about kubectl proxy.