Sign inSign up

readytalk/kube-vault-deploy

By readytalk

Updated over 7 years ago

Docker container for deploying to Kubernetes (via `kubectl` or `helm`) using Vault to authenticate.

Image
1

10K+

readytalk/kube-vault-deploy repository overview

Kubernetes Deployments w/ Vault

Docker container for deploying to Kubernetes (via kubectl or helm) using Vault to authenticate.

Prerequisites

  • Kubernetes cluster
  • Vault instance
  • Pre-loaded secret w/ Kubernetes config
  • LDAP configured (optional)

Usage

There are two primary use cases for using this container.

Dev/Local Deployments

Manual deployments to Kubernetes (via kubectl or helm) from individual workstation. This scenario can utilize LDAP or VAULT_TOKEN environment variable for authentication.

LDAP Method:

docker run --rm -it \
    --name=kube-vault-deploy \
    -e KUBE_CLUSTER=blue.my-domain.com \
    -e VAULT_ADDR=https://vault.my-domain.com:8200 \
    -e VAULT_KUBE_PATH=secret/kubernetes/blue.my-domain.com/kube-config \
    -v ~/.vault-token-deploy:/vault-token:rw \
    -v $(pwd)/deploy:/scripts:ro \
    readytalk/kube-vault-deploy
Pipeline Deployments

Scripted/Automated deployments to Kubernetes (via kubectl or helm) from CI tools such as Jenkins/Travis. This scenario will required that a VAULT_TOKEN be passed into the container for authentication.

docker run --rm \
    --name=kube-vault-deploy \
    -e AUTO_BUILD=true \
    -e KUBE_CLUSTER=blue.my-domain.com \
    -e VAULT_ADDR=https://vault.my-domain.com:8200 \
    -e VAULT_KUBE_PATH=secret/kubernetes/blue.my-domain.com/kube-config \
    -e VAULT_TOKEN=$VAULT_TOKEN \
    -v $(pwd)/deploy:/scripts:ro \
    readytalk/kube-vault-deploy
Environment Variables

To customize some properties of the container, the following environment variables can be passed via the -e parameter (one for each variable). Value of this parameter has the format <VARIABLE_NAME>=<VALUE>.

VariableDescriptionDefault/Required
VAULT_ADDRThe full address of the instance of vault to connect to. For example https://vault.my-domain.com:8200required
VAULT_TOKENVault token to use for authentication. If not set and AUTO_BUILD=false, will prompt for LDAP credentials.``
AUTO_BUILDFlag that controls the behavior of the authentication mechanism. If set to true, will not prompt for LDAP user/pass but instead will fail if VAULT_TOKEN is not provided.false
KUBE_CLUSTERThis is the name of the Kubernetes cluster you want to deploy to. For example blue.my-domain.com.required
SECRET_CONFIGJSON text representing secrets to pull from Vault. See Secret Config section below.``
SECRET_CONFIG_PATHPath for secret config file. See Secret Config section below. Will only be used if SECRET_CONFIG is not set.``
HELM_MATCH_SERVERIf set to true, downloads the helm version to match the version of the Tiller installed on the cluster.true
HELM_VERSIONIf set, overrides the container version of helm with the specified version.
KUBE_MATCH_SERVERIf set to true, downloads the kubectl version to match the version of the cluster.true
KUBE_VERSIONIf set, overrides the container version of kubectl with the specified version.
KOPS_VERSIONIf set, overrides the container version of kops with the specified version.
VAULT_MATCH_SERVERIf set to true, downloads the vault version to match the version of the cluster.true
VAULT_VERSIONIf set, overrides the container version of Vault with the specified version.

Additional environment variables can be passed in to be used by the deployment files.

Volume Mounts

The following table describes data volumes used by the container. The mappings are set via the -v parameter. Each mapping is specified with the following format: <HOST_DIR>:<CONTAINER_DIR>[:PERMISSIONS].

Container pathPermissionsDescription
/scriptsroThis location contains deploy scripts from your host that need to be accessible by the application.
/vault-tokenrwThis is an optional volume where the application stores the authenticated vault token. It is recommended this not be set for production/pipeline jobs. For local development, it is recommended you mount this to ~/.vault-token (be sure to create that file first or Docker will create it as a directory and it will fail) on the host so that you don't have to auth every time you run the container.
/bin-cacherwThis is an optional volume where custom binary versions (kubectl, vault, etc) will be stored. This can be mounted locally to cache these binaries so they don't have to be downloaded every run.
Secret Config

A secret config, which defines secret values to pull from Vault, can be passed into this container. For more detail on the config file format, see vault-to-envs tool. There are several ways to get the config into this container:

  • Include an environment variable SECRET_CONFIG which contains the config text (json).
  • Include a file named secret_config.json into the working directory of the container (most commonly by volume mounts)

Deployment Scripts

Scripts should be mounted from a local directory to /scripts inside the container (see Volume Mounts section above). By default, the container will run the deploy.sh file in this directory to kick off the build. This script can anything you want with kubectl or helm and can be augmented with additional environment variables you pass in.

Example

As an example, say we have a project with the following structure

deploy/
│   deploy.sh
│
└── helm_chart/
│   │   Chart.yaml
│   │   values.yaml
│   │   values-dev.yaml
│   │   values-prod.yaml
│   │
│   └───templates/
│       │   deployment.yaml
│       │   service.yaml
│       │   ...
src/
│   ...
lib/
│   ...
README.md
...

deploy/deploy.sh:

#!/bin/bash

helm upgrade --values helm_chart/values-$HELM_ENV.yaml $HELM_ENV-release helm_chart/

From the project root we can run

docker run --rm -it \
    --name=kube-vault-deploy \
    -e VAULT_ADDR=https://vault.my-domain.com:8200 \
    -e KUBE_CLUSTER=blue.my-domain.com \
    -e VAULT_KUBE_PATH=secret/kubernetes/blue.my-domain.com/kube-config \
    -e HELM_ENV=dev \
    -v $(pwd)/deploy:/scripts:ro \
    readytalk/kube-vault-deploy

From there the following will happen:

  • User will be prompted for a vault credentials (LDAP) since VAULT_TOKEN was not passed in.
  • Container will read the Kubernetes config from Vault field config in the secret secret/kubernetes/blue.my-domain.com/kube-config
  • Container will execute deploy.sh which was passed in from the volume mounted to deploy/
  • HELM_ENV is a custom environment variable used by deploy.sh
  • Within deploy.sh perform a helm upgrade

Tag summary

Content type

Image

Digest

Size

125.3 MB

Last updated

over 7 years ago

docker pull readytalk/kube-vault-deploy