If you cannot find Vault on the first page, use the search bar or navigate through the library.
Deploy HashiCorp Vault on Scaleway Kubernetes clusters using Easy Deploy
- hashicorp
- vault
- kubernetes
- k8s
- easy
- deploy
HashiCorp Vault is an identity-based secrets and encryption management system. It provides encryption services that are gated by authentication and authorization methods to ensure secure, auditable and restricted access to secrets. Vault is used to secure, store and protect secrets and other sensitive data using a UI, CLI, or HTTP API.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A valid API key
- Created a Scaleway Kubernetes Kapsule or Kosmos cluster
Deploying the Vault application using Easy Deploy
- In the Scaleway console, navigate to the Kubernetes section under Containers.
- Click the name of the cluster where you wish to deploy Grafana. The Cluster Information tab will display.
- Click the Easy Deploy tab. The application dashboard displays.
- Click Deploy Application. The application deployment wizard displays.
- Choose Application Library to see the list of available applications.
- Select the Vault application.
Tip
- Optionally, customize the default configuration for Vault using Helm Charts. If you do not need any customized configuration you can skip this step.
- Enter a name and a Kubernetes namespace for your application. If no name is entered, Grafana will be installed in the default namespace of the cluster.
- Click Deploy Application to deploy Grafana on your Kubernetes cluster.
Initializing and unsealing Vault
-
Check the status of your Vault using the
kubectl
command.kubectl get pods -l app.kubernetes.io/name=vaultTipIf you choose another name for your Vault application ensure to replace the application name with the corresponding value.
-
Initialize Vault. Replace
vault-0
with the name of your application. If your application is calledvault-application
the value will bevault-application-0
.kubectl exec -it vault-0 -- vault operator initImportantSave the unseal keys and the initial root token provided by the command.
-
Unseal Vault using three unseal keys retrieved in the previous step:
kubectl exec -it vault-0 -- vault operator unseal <unseal-key-1>kubectl exec -it vault-0 -- vault operator unseal <unseal-key-2>kubectl exec -it vault-0 -- vault operator unseal <unseal-key-3> -
Login to Vault using the initial root token generated in step two:
kubectl exec -it vault-0 -- vault login <initial-root-token> -
Enable the KV secrets engine at
secret/
:kubectl exec -it vault-0 -- vault secrets enable -path=secret kv-v2
Configure Vault for Kubernetes authentication
-
Enable Kubernetes authentication:
kubectl exec -it vault-0 -- vault auth enable kubernetes -
Enter the Vault shell:
kubectl exec -it vault-0 -- sh -
Paste the following configuration to configure Vault with the Kubernetes API:
vault write auth/kubernetes/config \kubernetes_host="https://<KUBERNETES_PORT_443_TCP_ADDR>:443" \token_reviewer_jwt="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \kubernetes_ca_cert="$(cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt)"exitReplace
<KUBERNETES_PORT_443_TCP_ADDR>
with the IP address of your Vault pod. You can retrieve it using thekubectl get svc
command. The pod name corresponds to your application name (e.g. if your application is called vault-application, the pod name will beapplication-vault
). -
Enter the Vault shell:
kubectl exec -it vault-0 -- sh -
Paste the following configuration to create a policy:
vault policy write myapp-kv-ro -<<EOFpath "secret/data/myapp/*" {capabilities = ["create", "read", "update", "delete", "list"]}EOFexit -
Enter the Vault shell:
kubectl exec -it vault-0 -- sh -
Paste the following configuration to create a role:
vault write auth/kubernetes/role/myapp \bound_service_account_names=myapp-sa \bound_service_account_namespaces=default \policies=myapp-kv-ro \ttl=24hexit
Storing and retrieving secrets
-
Enter the Vault shell:
kubectl exec -it vault-0 -- sh -
Store a secret in Vault:
vault kv put secret/myapp/config username='myuser' password='mypassword'exit -
Deploy an application with a service account that has access to the secrets stored in Vault.
-
Create a service account:
kubectl create serviceaccount myapp-sa -
Deploy your application:
apiVersion: apps/v1kind: Deploymentmetadata:name: myappspec:replicas: 1selector:matchLabels:app: myapptemplate:metadata:labels:app: myappspec:serviceAccountName: myapp-sacontainers:- name: myappimage: your-application-imageenv:- name: VAULT_ADDRvalue: "http://vault.default.svc.cluster.local:8200"- name: VAULT_TOKENvalueFrom:secretKeyRef:name: myapp-sa-tokenkey: token
-
-
Use a Vault client to retrieve the secrets within your application:
import hvacclient = hvac.Client(url='http://vault.default.svc.cluster.local:8200')client.token = os.getenv('VAULT_TOKEN')secret = client.secrets.kv.v2.read_secret_version(path='myapp/config')username = secret['data']['data']['username']password = secret['data']['data']['password']
By following these steps, you have been able to set up Vault on Kubernetes in a Private Network, store secret information, and securely retrieve it in your applications. For more information, refer to the official Vault documentation