Home > Net >  How to replace or get VCAP_SERVICES in Kubernetes
How to replace or get VCAP_SERVICES in Kubernetes

Time:04-25

I am working on migrating a spring boot app to kubernetes which is currently placed on PCF and it is using a configuration class where it is getting values from VCAP_SERVICES that is picked up using the environment.getProperty().

I need to know how to manage this on AKS as I think VCAP_Service is PCF specific.

Please help.

CodePudding user response:

In Kubernetes, you would use ConfigMap Secret as a replacement for VCAP_Service. Example of ConfigMap file called max_allowed_packet.cnf:

[mysqld]
max_allowed_packet = 64M

Example of a secret file called mysql-secret.yaml:

apiVersion: v1
kind: Secret
metadata:
  name: mariadb-root-password
type: Opaque
data:
  password: S3ViZXJuZXRlc1JvY2tzIQ=

kubectl apply -f mysql-secret.yaml

References: https://opensource.com/article/19/6/introduction-kubernetes-secrets-and-configmaps#:~:text=Kubernetes has two types of,or volumes or environment variables.

https://cloudnative101.dev/electives/cf-to-k8s/

CodePudding user response:

I would suggest you follow the Kubernetes Service Binding Spec.

It builds on top of Kubernetes Secrets and defines a standard layout for how those secrets are mounted into a container. Instead of using an environment variable like VCAP_SERVICES it defines a folder/file structure on disk. You mount the secrets into the container following the specification.

The advantage is that applications, libraries, and services can all work together by following the specification.

A couple of examples that work with the K8s service binding spec:

  1. If you're using Java & Spring Boot, the Spring Cloud Bindings library will automatically read bindings and map them to Spring Boot configuration properties. This is very similar to how libraries will read properties out of VCAP_SERVICES and configure your application.

  2. Cloud-Native buildpacks, in particular the Paketo Buildpacks implementations, will look for the presence of service bindings at build or run time to conditionally activate additional behaviors that require secret information such as credentials or license keys.

  • Related