github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/website/source/docs/providers/kubernetes/index.html.markdown (about) 1 --- 2 layout: "kubernetes" 3 page_title: "Provider: Kubernetes" 4 sidebar_current: "docs-kubernetes-index" 5 description: |- 6 The Kubernetes (K8s) provider is used to interact with the resources supported by Kubernetes. The provider needs to be configured with the proper credentials before it can be used. 7 --- 8 9 # Kubernetes Provider 10 11 The Kubernetes (K8S) provider is used to interact with the resources supported by Kubernetes. The provider needs to be configured with the proper credentials before it can be used. 12 13 Use the navigation to the left to read about the available resources. 14 15 -> **Note:** The Kubernetes provider is new as of Terraform 0.9. It is ready to be used but many features are still being added. If there is a Kubernetes feature missing, please report it in the GitHub repo. 16 17 ## Example Usage 18 19 ```hcl 20 provider "kubernetes" { 21 config_context_auth_info = "ops" 22 config_context_cluster = "mycluster" 23 } 24 25 resource "kubernetes_namespace" "example" { 26 metadata { 27 name = "my-first-namespace" 28 } 29 } 30 ``` 31 32 ## Authentication 33 34 There are generally two ways to configure the Kubernetes provider. 35 36 ### File config 37 38 The provider always first tries to load **a config file** from a given 39 (or default) location. Depending on whether you have current context set 40 this _may_ require `config_context_auth_info` and/or `config_context_cluster` 41 and/or `config_context`. 42 43 #### Setting default config context 44 45 Here's an example for how to set default context and avoid all provider configuration: 46 47 ``` 48 kubectl config set-context default-system \ 49 --cluster=chosen-cluster \ 50 --user=chosen-user 51 52 kubectl config use-context default-system 53 ``` 54 55 Read [more about `kubectl` in the official docs](https://kubernetes.io/docs/user-guide/kubectl-overview/). 56 57 ### Statically defined credentials 58 59 The other way is **statically** define all the credentials: 60 61 ```hcl 62 provider "kubernetes" { 63 host = "https://104.196.242.174" 64 username = "ClusterMaster" 65 password = "MindTheGap" 66 67 client_certificate = "${file("~/.kube/client-cert.pem")}" 68 client_key = "${file("~/.kube/client-key.pem")}" 69 cluster_ca_certificate = "${file("~/.kube/cluster-ca-cert.pem")}" 70 } 71 ``` 72 73 If you have **both** valid configuration in a config file and static configuration, the static one is used as override. 74 i.e. any static field will override its counterpart loaded from the config. 75 76 ## Argument Reference 77 78 The following arguments are supported: 79 80 * `host` - (Optional) The hostname (in form of URI) of Kubernetes master. Can be sourced from `KUBE_HOST`. Defaults to `https://localhost`. 81 * `username` - (Optional) The username to use for HTTP basic authentication when accessing the Kubernetes master endpoint. Can be sourced from `KUBE_USER`. 82 * `password` - (Optional) The password to use for HTTP basic authentication when accessing the Kubernetes master endpoint. Can be sourced from `KUBE_PASSWORD`. 83 * `insecure`- (Optional) Whether server should be accessed without verifying the TLS certificate. Can be sourced from `KUBE_INSECURE`. Defaults to `false`. 84 * `client_certificate` - (Optional) PEM-encoded client certificate for TLS authentication. Can be sourced from `KUBE_CLIENT_CERT_DATA`. 85 * `client_key` - (Optional) PEM-encoded client certificate key for TLS authentication. Can be sourced from `KUBE_CLIENT_KEY_DATA`. 86 * `cluster_ca_certificate` - (Optional) PEM-encoded root certificates bundle for TLS authentication. Can be sourced from `KUBE_CLUSTER_CA_CERT_DATA`. 87 * `config_path` - (Optional) Path to the kube config file. Can be sourced from `KUBE_CONFIG`. Defaults to `~/.kube/config`. 88 * `config_context` - (Optional) Context to choose from the config file. Can be sourced from `KUBE_CTX`. 89 * `config_context_auth_info` - (Optional) Authentication info context of the kube config (name of the kubeconfig user, `--user` flag in `kubectl`). Can be sourced from `KUBE_CTX_AUTH_INFO`. 90 * `config_context_cluster` - (Optional) Cluster context of the kube config (name of the kubeconfig cluster, `--cluster` flag in `kubectl`). Can be sourced from `KUBE_CTX_CLUSTER`.