*[Accessing services running on the cluster](#otherservices)
*[Requesting redirects](#redirect)
*[Requesting redirects](#redirect)
*[So many proxies](#somanyproxies)
## Accessing the cluster API<a name="api"></a>
### Accessing for the first time with kubectl
When accessing the Kubernetes API for the first time, we suggest using the
kubernetes CLI, `kubectl`.
To access a cluster, you need to know the location of the cluster and have credentials
to access it. Typically, this is automatically set-up when you work through
though a [Getting started guide](../docs/getting-started-guide/README.md),
or someone else setup the cluster and provided you with credentials and a location.
Check the location and credentials that kubectl knows about with this command:
```
kubectl config view
```
.
## <a name="proxy"></a>Using the Kubernetes proxy to access the cluster
Many of the [examples](../examples/README.md) provide an introduction to using
Information about the cluster can be accessed by using a proxy URL and the cluster authentication keys.
kubectl and complete documentation is found in the [kubectl manual](../docs/kubectl.md).
For example, if a cluster has cluster-level logging enabled (using Elasticsearch), you can retrieve information about the Elasticsearch logging on that cluster through a proxy URL.
### Retrieving the authentcation keys and proxy URLs
### <a name="kubectlproxy"</a>Directly accessing the REST API
Use `kubectl` commands to retrieve the access information.
Kubectl handles locating and authenticating to the apiserver.
If you want to directly access the REST API with an http client like
curl or wget, or a browser, there are several ways to locate and authenticate:
- Run kubectl in proxy mode.
- Recommended approach.
- Uses stored apiserver location.
- Verifies identity of apiserver using self-signed cert. No MITM possible.
- Authenticates to apiserver.
- In future, may do intelligent client-side load-balancing and failover.
- Provide the location and credentials directly to the http client.
- Alternate approach.
- Works with some types of client code that are confused by using a proxy.
- Need to import a root cert into your browser to protect against MITM.
To retrieve the authentication keys for your clusters, run the following command:
#### Using kubectl proxy
The following command runs kubectl in a mode where it acts as a reverse proxy. It handles
locating the apiserver and authenticating.
Run it like this:
```
kubectl proxy --port=8080 &
```
```
$ kubectl config view
See [kubectl proxy](../docs/kubectl-proxy.md) for more details.
...
Then you can explore the API with curl, wget, or a browser, like so:
users:
```
- name: kubernetes_logging
$ curl http://localhost:8080/api
user:
{
client-certificate-data: REDACTED
"versions": [
client-key-data: REDACTED
"v1"
token: cvIH2BYtNS85QG0KSLHgl5Oba4YNQOrx
]
- name: kubernetes_logging-basic-auth
}
user:
```
password: 4mty0Vl9nNFfwLJz
#### Without kubectl proxy
username: admin
It is also possible to avoid using kubectl proxy by passing an authentication token
- Depending on your cluster environment, this may just expose the service to your corporate network,
or it may expose it to the internet. Think about whether the service being exposed is secure.
Does it do its own authentication?
- Place pods behind services. To access one specific pod from a set of replicas, such as for debugging,
place a unique label on the pod it and create a new service which selects this label.
- In most cases, it should not be necessary for application developer to directly access
nodes via their nodeIPs.
- Access services, nodes, or pods using the Proxy Verb.
- Does apiserver authentication and authorization prior to accessing the remote service.
Use this if the services are not secure enough to expose to the internet, or to gain
access to ports on the node IP, or for debugging.
- Proxies may cause problems for some web applications.
- Only works for HTTP/HTTPS.
- Described in [using the apiserver proxy](#apiserverproxy).
- Access from a node or pod in the cluster.
- Run a pod, and then connect to a shell in it using [kubectl exec](../docs/kubectl_exec.md).
Connect to other nodes, pods, and services from that shell.
- Some clusters may allow you to ssh to a node in the cluster. From there you may be able to
access cluster services. This is a non-standard method, and will work on some clusters but
not others. Browsers and other tools may or may not be installed. Cluster DNS may not work.
### Discovering builtin services
Typically, there are several services which are started on a cluster by default. Get a list of these
with the `kubectl cluster-info` command:
```
```
$ kubectl cluster-info
$ kubectl cluster-info
...
@@ -38,10 +167,13 @@ $ kubectl cluster-info
...
@@ -38,10 +167,13 @@ $ kubectl cluster-info
grafana is running at https://104.197.5.247/api/v1/proxy/namespaces/default/services/monitoring-grafana
grafana is running at https://104.197.5.247/api/v1/proxy/namespaces/default/services/monitoring-grafana
heapster is running at https://104.197.5.247/api/v1/proxy/namespaces/default/services/monitoring-heapster
heapster is running at https://104.197.5.247/api/v1/proxy/namespaces/default/services/monitoring-heapster
```
```
This shows the proxy-verb URL for accessing each service.
For example, this cluster has cluster-level logging enabled (using Elasticsearch), which can be reached
at `https://104.197.5.247/api/v1/proxy/namespaces/default/services/elasticsearch-logging/` if suitable credentials are passed, or through a kubectl proxy at, for example:
(See [above](#api) for how to pass credentials or use kubectl proxy.)
**Note**: Currently, adding trailing forward slashes '.../' to proxy URLs is required, for example: `https://104.197.5.247/api/v1/proxy/namespaces/default/services/elasticsearch-logging/`.
#### Manually constructing apiserver proxy URLs
#### Manually constructing proxy URLs
As mentioned above, you use the `kubectl cluster-info` command to retrieve the service's proxy URL. To create proxy URLs that include service endpoints, suffixes, and parameters, you simply append to the service's proxy URL:
As mentioned above, you use the `kubectl cluster-info` command to retrieve the service's proxy URL. To create proxy URLs that include service endpoints, suffixes, and parameters, you simply append to the service's proxy URL:
@@ -63,49 +195,12 @@ As mentioned above, you use the `kubectl cluster-info` command to retrieve the s
...
@@ -63,49 +195,12 @@ As mentioned above, you use the `kubectl cluster-info` command to retrieve the s
}
}
```
```
### Accessing cluster information
#### Using web browsers to access services running on the cluster
You can run `curl` commands or use a web browser to access the information about cluster services. Depending on how secure the information is, you can choose to use basic authentication or token authentication (bearer and insecure).
You may be able to put a apiserver proxy url into the address bar of a browser. However:
- Web browsers cannot usually pass tokens, so you may need to use basic (password) auth. Apiserver can be configured to accespt basic auth,
#### Using `curl` commands
but your cluster may not be configured to accept basic auth.
Run `curl` commands using the following formats:
- Some web apps may not work, particularly those with client side javascript that construct urls in a
In a web browser, navigate to the proxy URL and then enter your username and password when prompted. For example, you would copy and paste the following proxy URL into the address bar of your browser: