Skip to content

Commit 353b94a

Browse files
authored
Update authentication section of docs (#1132)
1 parent 7289d86 commit 353b94a

File tree

1 file changed

+32
-39
lines changed

1 file changed

+32
-39
lines changed

website/docs/index.html.markdown

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,69 +52,60 @@ For specific usage examples, see the guides for [AKS](https://github.com/hashico
5252

5353
## Authentication
5454

55-
There are generally two ways to configure the Kubernetes provider.
55+
The Kubernetes provider can get its configuration in two ways:
5656

57-
### File config
57+
1. _Explicitly_ by supplying attributes to the provider block. This includes:
58+
* [Using a kubeconfig file](#file-config)
59+
* [Supplying credentials](#credentials-config)
60+
* [Exec plugins](#exec-plugins)
61+
2. _Implicitly_ through environment variables. This includes:
62+
* [Using the in-cluster config](#in-cluster-config)
5863

59-
The provider always first tries to load **a config file** from a given
60-
(or default) location. Depending on whether you have a current context set
61-
this _may_ require `config_context_auth_info` and/or `config_context_cluster`
62-
and/or `config_context`.
64+
For a full list of supported provider authentication arguments and their corresponding environment variables, see the [argument reference](#argument-reference) below.
6365

64-
#### Setting default config context
6566

66-
Here's an example of how to set default context and avoid all provider configuration:
67+
### File config
6768

68-
```
69-
kubectl config set-context default-system \
70-
--cluster=chosen-cluster \
71-
--user=chosen-user
69+
The easiest way is to supply a path to your kubeconfig file using the `config_path` attribute or using the `KUBE_CONFIG_PATH` environment variable. A kubeconfig file may have multiple contexts. If `config_context` is not specified, the provider will use the `default` context.
7270

73-
kubectl config use-context default-system
71+
```hcl
72+
provider "kubernetes" {
73+
config_path = "~/.kube/config"
74+
}
7475
```
7576

76-
Read [more about `kubectl` in the official docs](https://kubernetes.io/docs/user-guide/kubectl-overview/).
77-
78-
### In-cluster service account token
79-
80-
If no other configuration is specified, and when it detects it is running in a kubernetes pod,
81-
the provider will try to use the service account token from the `/var/run/secrets/kubernetes.io/serviceaccount/token` path.
82-
Detection of in-cluster execution is based on the sole availability of both of the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables,
83-
with non-empty values.
84-
85-
If you have any other static configuration setting specified in a config file or static configuration, in-cluster service account token will not be tried.
86-
87-
### Statically defined credentials
88-
89-
Another way is **statically** define TLS certificate credentials:
77+
The provider also supports multiple paths in the same way that kubectl does using the `config_paths` attribute or `KUBE_CONFIG_PATHS` environment variable.
9078

9179
```hcl
9280
provider "kubernetes" {
93-
host = "https://104.196.242.174"
94-
95-
client_certificate = "${file("~/.kube/client-cert.pem")}"
96-
client_key = "${file("~/.kube/client-key.pem")}"
97-
cluster_ca_certificate = "${file("~/.kube/cluster-ca-cert.pem")}"
81+
config_paths = [
82+
"/path/to/config_a.yaml",
83+
"/path/to/config_b.yaml"
84+
]
9885
}
9986
```
10087

101-
or username and password (HTTP Basic Authorization):
88+
### Credentials config
89+
90+
You can also configure the host, basic auth credentials, and client certificate authentication explicitly or through environment variables.
10291

10392
```hcl
10493
provider "kubernetes" {
105-
host = "https://104.196.242.174"
94+
host = "https://cluster_endpoint:port"
10695
107-
username = "username"
108-
password = "password"
96+
client_certificate = file("~/.kube/client-cert.pem")
97+
client_key = file("~/.kube/client-key.pem")
98+
cluster_ca_certificate = file("~/.kube/cluster-ca-cert.pem")
10999
}
110100
```
111101

102+
### In-cluster Config
112103

104+
The provider uses the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables to detect when it is running inside a cluster, so in this case you do not need to specify any attributes in the provider block if you want to connect to the local kubernetes cluster.
113105

114-
~> If you have **both** valid configurations in a config file and static configuration, the static one is used as an override.
115-
i.e. any static field will override its counterpart loaded from the config.
106+
If you want to connect to a different cluster than the one terraform is running inside, configure the provider as [above](#credentials-config).
116107

117-
## Exec-based credential plugins
108+
## Exec plugins
118109

119110
Some cloud providers have short-lived authentication tokens that can expire relatively quickly. To ensure the Kubernetes provider is receiving valid credentials, an exec-based plugin can be used to fetch a new token before initializing the provider. For example, on EKS, the command `eks get-token` can be used:
120111

@@ -130,6 +121,8 @@ provider "kubernetes" {
130121
}
131122
```
132123

124+
## Examples
125+
133126
For further reading, see these examples which demonstrate different approaches to keeping the cluster credentials up to date: [AKS](https://github.com/hashicorp/terraform-provider-kubernetes/blob/master/_examples/aks/README.md), [EKS](https://github.com/hashicorp/terraform-provider-kubernetes/blob/master/_examples/eks/README.md), and [GKE](https://github.com/hashicorp/terraform-provider-kubernetes/blob/master/_examples/gke/README.md).
134127

135128

0 commit comments

Comments
 (0)