Docker container for deploying to Kubernetes (via `kubectl` or `helm`) using Vault to authenticate.
10K+
Docker container for deploying to Kubernetes (via kubectl or helm) using Vault to authenticate.
There are two primary use cases for using this container.
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
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
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>.
| Variable | Description | Default/Required |
|---|---|---|
VAULT_ADDR | The full address of the instance of vault to connect to. For example https://vault.my-domain.com:8200 | required |
VAULT_TOKEN | Vault token to use for authentication. If not set and AUTO_BUILD=false, will prompt for LDAP credentials. | `` |
AUTO_BUILD | Flag 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_CLUSTER | This is the name of the Kubernetes cluster you want to deploy to. For example blue.my-domain.com. | required |
SECRET_CONFIG | JSON text representing secrets to pull from Vault. See Secret Config section below. | `` |
SECRET_CONFIG_PATH | Path for secret config file. See Secret Config section below. Will only be used if SECRET_CONFIG is not set. | `` |
HELM_MATCH_SERVER | If set to true, downloads the helm version to match the version of the Tiller installed on the cluster. | true |
HELM_VERSION | If set, overrides the container version of helm with the specified version. | |
KUBE_MATCH_SERVER | If set to true, downloads the kubectl version to match the version of the cluster. | true |
KUBE_VERSION | If set, overrides the container version of kubectl with the specified version. | |
KOPS_VERSION | If set, overrides the container version of kops with the specified version. | |
VAULT_MATCH_SERVER | If set to true, downloads the vault version to match the version of the cluster. | true |
VAULT_VERSION | If 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.
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 path | Permissions | Description |
|---|---|---|
/scripts | ro | This location contains deploy scripts from your host that need to be accessible by the application. |
/vault-token | rw | This 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-cache | rw | This 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. |
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:
SECRET_CONFIG which contains the config text (json).secret_config.json into the working directory of the container (most commonly by volume mounts)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.
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:
config in the secret secret/kubernetes/blue.my-domain.com/kube-configdeploy.sh which was passed in from the volume mounted to deploy/HELM_ENV is a custom environment variable used by deploy.shdeploy.sh perform a helm upgradeContent type
Image
Digest
Size
125.3 MB
Last updated
over 7 years ago
docker pull readytalk/kube-vault-deploy