This provider is a fork of the official Kubernetes provider developed by HashiCorp.
Status
This fork is no longer supported or maintained.
The official Terraform provider is being supported by a full time HashiCorp engineer and all resources this fork provided are available in the official build 🎉 🎉 🎉
Cluster RoleAdded to official provider v1.5.1Cluster Role BindingAdded to official provider v1.3.0Cron JobAdded to official provider v1.8.0DaemonsetAdded to official provider v1.5.1DeploymentAdded to official provider v1.3.0IngressAdded to official provider v1.7.0JobAdded to official provider v1.8.0RoleAdded to official provider v1.5.0Role BindingAdded to official provider v1.5.0Stateful SetAdded to official provider v1.4.0
The latest build of this provider uses v6.0 of the kubernetes client-go library, and has been tested with the following Kubernetes versions:
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
Clone repository to: $GOPATH/src/github.com/sl1pm4t/terraform-provider-kubernetes
$ mkdir -p $GOPATH/src/github.com/sl1pm4t; cd $GOPATH/src/github.com/sl1pm4t
$ git clone https://github.com/sl1pm4t/terraform-provider-kubernetes
Enter the provider directory and build the provider
$ cd $GOPATH/src/github.com/sl1pm4t/terraform-provider-kubernetes
$ make build
Alternatively, use the golang docker to build the provider
- clone this repo: https://github.com/sl1pm4t/terraform-provider-kubernetes.git
- run:
cd <path to cloned repo>
docker run --rm -v `pwd`:/go/src/github.com/sl1pm4t/terraform-provider-kubernetes/ \
-w /go/src/github.com/sl1pm4t/terraform-provider-kubernetes/ \
-e GOOS=windows -e GOARCH=386 golang \
go build -v
be sure to use the appropriate OS and architecture for your environment (see official docker for golang)
- From the root director of your terraform project, run
terraform init --plugin-dir=<location of the plugin executable built in step 2>`
Provider Configuration
provider kubernetes {
# leave blank to pickup config from kubectl config of local system
}
provider "kubernetes" {
host = "https://104.196.242.174"
username = "ClusterMaster"
password = "MindTheGap"
client_certificate = "${file("~/.kube/client-cert.pem")}"
client_key = "${file("~/.kube/client-key.pem")}"
cluster_ca_certificate = "${file("~/.kube/cluster-ca-cert.pem")}"
}
After this fork has been downloaded and built into $GOPATH
(as in the
previous step), specify the location of the built binaries when
initialising the project:
$ terraform init -plugin-dir=$GOPATH/bin
This step is important in order to make terraform actually use this fork
of the kubernetes provider. If you fail to do this upon the first init
the official provider is downloaded instead.
If this happens, delete the .terraform/
folder that has been created
inside your project folder and perform the above init again.
Deployment Resource
resource "kubernetes_deployment" "nginx" {
metadata {
name = "nginx"
namespace = "web"
}
spec {
selector {
app = "nginx"
}
template {
metadata {
labels {
app = "nginx"
}
}
spec {
container {
image = "nginx:1.8"
name = "app"
resources {
requests {
memory = "1Gi"
cpu = "1"
}
limits {
memory = "2Gi"
cpu = "2"
}
}
readiness_probe {
http_get {
path = "/health"
port = "90"
}
initial_delay_seconds = 10
period_seconds = 10
}
liveness_probe {
exec {
command = ["/bin/health"]
}
initial_delay_seconds = 120
period_seconds = 15
}
env {
name = "CONFIG_FILE_LOCATION"
value = "/etc/app/config"
}
port {
container_port = 80
}
volume_mount {
name = "config"
mount_path = "/etc/app/config"
}
}
init_container {
name = "helloworld"
image = "debian"
command = ["/bin/echo", "hello", "world"]
}
volume {
name = "config"
config_map {
name = "app-config"
}
}
}
}
}
}
If you wish to work on the provider, you'll first need Go installed on your machine (version 1.9+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin
to your $PATH
.
To compile the provider, run make build
. This will build the provider and put the provider binary in the $GOPATH/bin
directory.
$ make build
...
$ $GOPATH/bin/terraform-provider-kubernetes
...
In order to test the provider, you can simply run make test
.
$ make test
In order to run the full suite of Acceptance tests, run make testacc
.
Note: Acceptance tests create real resources, and often cost money to run.
$ make testacc