Giter VIP home page Giter VIP logo

terraform-provider-kubernetes's Introduction

Kubernetes Terraform Provider

This provider is a fork of the official Kubernetes provider developed by HashiCorp. This fork supports the following resources in addition to the official provider:

  • Cluster Role kubernetes_cluster_role
  • Cluster Role Binding kubernetes_cluster_role_binding
  • Cron Job kubernetes_cron_job
  • Daemonset kubernetes_daemonset
  • Deployment kubernetes_deployment
  • Ingress kubernetes_ingress
  • Job kubernetes_job
  • Role kubernetes_role
  • Role Binding kubernetes_role_binding
  • Stateful Set kubernetes_stateful_set

Supported Kubernetes Versions

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

Requirements

  • Terraform 0.11.x
  • Go 1.10 (to build the provider plugin)

Building The Provider

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

  1. clone this repo: https://github.com/sl1pm4t/terraform-provider-kubernetes.git
  2. 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)

  1. From the root director of your terraform project, run
terraform init --plugin-dir=<location of the plugin executable built in step 2>`

Using the provider

Provider Configuration

Simplest - kubectl configuration
provider kubernetes {
  # leave blank to pickup config from kubectl config of local system
}
Explicit configuration
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")}"
}
Initialise provider with plugin directory

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"
          }
        }

      }
    }
  }
}

Developing the Provider

Development Environment

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

terraform-provider-kubernetes's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.