-
Notifications
You must be signed in to change notification settings - Fork 3
Getting started
- MacOS/Linux
- JDK 11+
- oc (OpenShift cli)
It's highly recommended to get familiar with microconfig first.
Example osdf repository is here.
In this tutorial we will describe repo structure and some key components
To start, there are two environments - dev and prod. Their descriptions are located in repo/envs folder, both are derived from fictional base env with the list of all our components.
All microconfig components are located in components folder, every folder (and all sub-folders) inside 'components' directory is a valid component so you are free to choose how to structure your configs
In this example, we have three apps: frontend, backend and auth.
Components that will represent these apps are located in components/apps dir, and we also listed them in our base.yaml environment description:
main: # group name
components:
- backend
- frontend
- auth
After microconfig build, our app components must comply with osdf requirements:
- component must have
resourcessub-directory with kubernetes resources inside - component must have
deploy.yamlwith requiredapp.versionandconfig.versionproperties
To create deploy.yaml file, we can store our configs in .deploy files.
Let's try to make sense out of backend component
service.deploy file has main configuration properties
#include k8s-service # use k8s-service component as a template
app.version: 1.1 # set app version to 1.1
osdf.configmap.backend: # tell osdf to create configmap from application.yaml file
name: backend
files:
- application.yaml
k8s-service is a helper component which has templates for Deployment and Service resources with placeholders and other configuration. This is needed to:
- avoid copy paste of nearly identical kubernetes resources across our apps.
- share common configuration (
versionsin our example)
k8s-service/template.deploy
#include versions
mc.template.service: ${k8s-service@configDir}/deployment-and-service.yaml -> resources/deployment-and-service.yaml # generate template
image.version: ${this@app.version} # set image.version (used as placeholder in Deployment) to match app.version
server.port: ${app::this@server.port:8080} # set server.port to match port defined in application configs (common case in spring apps)
version component has required app.version and config.version properties.
app.version: ${process::versions@project.version}
config.version: ${process::versions@config.version}
Note that we set them using properties from config-version.proc and project-version.proc. This is needed to be able dynamically change image version (and config version if needed) using osdf:
- deployment has
${this@image.version}placeholder -
image.versionequalsapp.version -
app.versionequalsproject.version(from project-version.proc) -
project.versioninproject-version.procis modified dynamically by osdf
Suppose that we want to have Route resource in dev environment for our backend app for debugging purposes (we don't want to have it in production environment, we will only expose fronend app). We can do that by creating *.dev.deploy* file with required instructions. In this example, this is done in route.dev.deploy file.
All our apps use k8s-service as template, but each one of them has some service specific overrides or additions. For example:
-
authgenerateslogback.xmltemplate -
backendhas fixedapp.versionproperty -
frontendhas differentserver.portand hasrouteinclusion for all envs
Using microconfig, it's possible to create complex yet readable configuration for microservices without having to copypaste common properties across apps and environments.
components/system/k8s-cluster component contains cluster properties:
-
project- kubernetes namespace -
cluster.url.api- api url of your OpenShift cluster
Note that we have defined separate properties for each env
Now let's try to deploy these apps using osdf. Firstly, we have to initialize osdf with our repository, OpenShift credentials, environment and versions.
~ osdf init local-configs -p /path/to/configs -v tutorial # initialize from local-configs, set config-version to 'tutorial'
Environment is not specified
~ osdf env dev # set dev environment
...microconfig output...
~ osdf versions -pv 1.0 # set `app.version` to 1.0
...microconfig output...
~ osdf init openshift -c user:pass # set openshift credentials
And deploy all apps
~ osdf deploy # deploys all apps by default
Deploying: frontend backend auth
Deploying group - [frontend, backend, auth]
frontend OK
backend OK
auth OK
OK
Check their status using osdf status command:
~ osdf status
COMPONENT VERSION CONFIGS STATUS REPLICAS
frontend 1.0 tutorial READY 1/1
backend 1.1 tutorial READY 1/1
auth 1.0 tutorial READY 1/1
Full docs are available here - https://github.com/microconfig/osdf/wiki/Docs