Azure Kubernetes Service (AKS) with Azure Key Vault (AKV) Part 1 — Secrets Store CSI

Step-By-Step Guidance

  1. Create an AKS resource: Create a resource group then an AKS cluster
  2. Create an AKV resource
az keyvault create -g <resource group name> -n <key vault name> --location <Ex: westus2, eastus...>
kubectl create ns <namespace name>
export SERVICE_PRINCIPAL_CLIENT_SECRET="$(az ad sp create-for-rbac --skip-assignment --name http://secrets-store-test --query 'password' -otsv)"export SERVICE_PRINCIPAL_CLIENT_ID="$(az ad sp show --id http://secrets-store-test --query 'appId' -otsv)"az keyvault set-policy -n <AKV name> --secret-permissions get --spn ${SERVICE_PRINCIPAL_CLIENT_ID}
# Create a secret with AAD SP client ID and secret
kubectl create secret generic secrets-store-creds --from-literal clientid=${SERVICE_PRINCIPAL_CLIENT_ID} --from-literal clientsecret=${SERVICE_PRINCIPAL_CLIENT_SECRET} -n <namespace name>
# Label the just-created secret
kubectl label secret secrets-store-creds
# Check whether the secret has been created in the environment
kubectl get secrets secrets-store-cred -n <namespace name>
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-out ingress-tls.crt \
-keyout ingress-tls.key \
-subj "/"
# export the a .pfx file with both .crt and .key
# skip Password prompt
openssl pkcs12 -export -in ingress-tls.crt -inkey ingress-tls.key -out <certificate name>.pfx

az keyvault certificate import --vault-name <AKV name> -n <certificate name> -f <certificate name>.pfx
# Check whether the certificate has been imported
az keyvault certificate list --vault-name <AKV name>
# the content of secretproviderclass.yaml
kind: SecretProviderClass
name: azure-tls
provider: azure
- secretName: ingress-tls-csi
- objectName: <certificate name>
key: tls.key
- objectName: <certificate name>
key: tls.crt
usePodIdentity: "false"
keyvaultName: <AKV name> # the name of the KeyVault
objects: |
- |
objectName: <certificate name>
objectType: secret
tenantId: <AAD tenant ID> # the tenant ID of the KeyVault
# create the secret provider class
kubectl apply -f secretproviderclass.yaml -n <namespace name>
# Check whether secretproviderclass has been created successfully
kubectl get secretproviderclasss -n <namespace name>
# add and HELM repo
helm repo add ingress-nginx
# update HELM repo
helm repo update
# create the NGINX Ingress Controller with HELM
helm install ingress-nginx/ingress-nginx --generate-name \
--namespace <namespace name> \
--set controller.replicaCount=2 \
--set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
-f - <<EOF
- name: secrets-store-inline
readOnly: true
secretProviderClass: "azure-tls"
name: secrets-store-creds
- name: secrets-store-inline
mountPath: "/mnt/secrets-store"
readOnly: true
# Check whether all related resources are up and running, especially the secret "ingress-tls-csi"
kubectl get deploy,pod,svc,ing,secret -n <namespace name>
# create app 1
kubectl apply -f -n <namespace name>
# create app 2
kubectl apply -f -n <namespace name>
# create Ingress
kubectl apply -f -n <namespace name>
# Check whether all related resources are up and running
kubectl get deploy,pod,svc,ing -n <namespace name>
# Get Ingress public IP address
kubectl get ing -n <namespace name>
# curl the service
curl -v -k --resolve<public IP address>
Error from server (InternalError): error when creating "": Internal error occurred: failed calling webhook "": Post "https://ingress-nginx-1617752626-controller-admission.ingress-test.svc:443/networking/v1beta1/ingresses?timeout=10s": service "ingress-nginx-1617752626-controller-admission" not found
# Get Ingress service
kubectl get svc -n <namespace name>
# Get all ValidatingWebhookConfigurations
kubectl get ValidatingWebhookConfiguration -n <namespace name>
# Delete every ValidatingWebhookConfigurations that does not have the same naming convention you are seeing in Ingress service
kubectl delete ValidatingWebhookConfiguration -n <namespace name>



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Learning new things about Kubernetes every day. Hopefully, the learning notes could help people on the same journey!