You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/index.html.markdown
+32-39Lines changed: 32 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,69 +52,60 @@ For specific usage examples, see the guides for [AKS](https://github.com/hashico
52
52
53
53
## Authentication
54
54
55
-
There are generally two ways to configure the Kubernetes provider.
55
+
The Kubernetes provider can get its configuration in two ways:
56
56
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)
58
63
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.
63
65
64
-
#### Setting default config context
65
66
66
-
Here's an example of how to set default context and avoid all provider configuration:
67
+
### File config
67
68
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.
72
70
73
-
kubectl config use-context default-system
71
+
```hcl
72
+
provider "kubernetes" {
73
+
config_path = "~/.kube/config"
74
+
}
74
75
```
75
76
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.
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.
113
105
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).
116
107
117
-
## Exec-based credential plugins
108
+
## Exec plugins
118
109
119
110
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:
120
111
@@ -130,6 +121,8 @@ provider "kubernetes" {
130
121
}
131
122
```
132
123
124
+
## Examples
125
+
133
126
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).
0 commit comments