|
--- |
|
apiVersion: v1 |
|
kind: ServiceAccount |
|
metadata: |
|
name: vault |
|
--- |
|
apiVersion: rbac.authorization.k8s.io/v1beta1 |
|
kind: ClusterRoleBinding |
|
metadata: |
|
name: vault-auth-delegator |
|
roleRef: |
|
apiGroup: rbac.authorization.k8s.io |
|
kind: ClusterRole |
|
name: system:auth-delegator |
|
subjects: |
|
- kind: ServiceAccount |
|
name: vault |
|
namespace: default |
|
--- |
|
apiVersion: apps/v1 |
|
kind: Deployment |
|
metadata: |
|
name: vault |
|
labels: |
|
run: vault |
|
spec: |
|
replicas: 1 |
|
selector: |
|
matchLabels: |
|
run: vault |
|
template: |
|
metadata: |
|
labels: |
|
run: vault |
|
spec: |
|
serviceAccountName: vault |
|
containers: |
|
- name: vault |
|
image: vault |
|
args: [ "server", "-dev", "-dev-listen-address=0.0.0.0:8200", "-dev-root-token-id=$(VAULT_TOKEN)" ] |
|
env: |
|
- name: VAULT_ADDR |
|
value: http://localhost:8200 |
|
- name: VAULT_TOKEN |
|
value: root-token |
|
ports: |
|
- containerPort: 8200 |
|
name: vault |
|
lifecycle: |
|
postStart: |
|
exec: |
|
command: |
|
- /bin/sh |
|
- -c |
|
- | |
|
{ |
|
set -ex |
|
# Wait for Vault server to start |
|
until vault status; do |
|
sleep 3 |
|
done |
|
# Ensure that Vault token is valid |
|
vault token lookup |
|
# Enable Kubernetes auth |
|
vault auth enable kubernetes |
|
# Configure Kubernetes auth |
|
vault write auth/kubernetes/config \ |
|
kubernetes_host=https://kubernetes \ |
|
kubernetes_ca_cert=@/run/secrets/kubernetes.io/serviceaccount/ca.crt \ |
|
token_reviewer_jwt=@/run/secrets/kubernetes.io/serviceaccount/token |
|
# Read the new Kubernetes auth configuration |
|
vault read auth/kubernetes/config |
|
# Create a simple policy for the demo app to use |
|
echo '{"path": {"secret/data/app/*": {"capabilities": ["read"]}}}' | vault policy write app - |
|
# Create a role for the demo app to login with |
|
vault write auth/kubernetes/role/app \ |
|
bound_service_account_names=app \ |
|
bound_service_account_namespaces=default \ |
|
policies=app \ |
|
ttl=4h |
|
# Read the new role configuration |
|
vault read auth/kubernetes/role/app |
|
# Create an example static KV secret for the demo app to read |
|
vault kv put secret/app/db username=app password=abc123 |
|
} 2>&1 | tee /postStart.log |
|
--- |
|
apiVersion: v1 |
|
kind: Service |
|
metadata: |
|
name: vault |
|
spec: |
|
ports: |
|
- port: 80 |
|
targetPort: vault |
|
selector: |
|
run: vault |