### Deploy Grafana with Octoploy Source: https://github.com/davidgiga1993/octoploy/blob/main/examples/grafana/README.md Deploys the Grafana example using Octoploy. Requires the DOMAIN variable to be set in _index.yml. ```bash python deploy.py --config-dir examples deploy grafana ``` -------------------------------- ### Install octoploy with pip Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Install the octoploy package using pip. Requires Python 3.9 or later and kubectl or oc in the PATH. ```bash pip install octoploy ``` -------------------------------- ### App config _index.yml sample Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Sample _index.yml app configuration. Shows all available parameters including name, type, templates, includes, on-config-change actions, vars, params, and configmaps. ```yml # Name of the deployment, available as APP_NAME variable name: 'my-app' ##################### # OPTIONAL SECTION ##################### # The type defines how the app will be used. # Can be "app" (default) or "template" type: 'app' # Template which should be applied, none by default applyTemplates: [ ] # Templates which should be applied AFTER processing the other templates and base yml files postApplyTemplates: [ ] includes: # List of additional k8s files that should be included # and are located outside of this app folder. # All paths are relative to this config file. k8s: [ ] # Action which should be executed if a configmap has been changed on-config-change: # Available options: # deploy (triggers a restart of the deployment) - deploy # exec (Executes a command inside the running container) - exec: command: /bin/sh args: - "-c" - "kill -HUP $(ps a | grep prometheus | grep -v grep | awk '{print $1}')" # Additional variables which are used for replacements vars: NSQ_NAME: 'nsq-core' # Required parameters which must be passed to this app. # This can be done via the CLI or if this app is a template the referring app can define it in "vars" params: - PASSWORD # File based configmaps # More modes available, see below configmaps: - name: nginx-config files: - file: "nginx.conf" ``` -------------------------------- ### Plan changes with octoploy plan / plan-all Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Lists changes to be applied for a specific app or all apps. The same commands as deploy but for planning. ```bash octoploy plan / plan-all ``` -------------------------------- ### Root config _root.yml sample Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Sample _root.yml configuration. Defines the namespace, context, optional stateName, global variables, and libraries to inherit. ```yml # Name of the k8s namespace / openshift project namespace: 'my-project' # K8s context which should be used for deploying context: 'my-k8s-cluster-config' ##################### # OPTIONAL SECTION ##################### # Name of the configmap which should hold the octoploy state stateName: 'octoploy-state' # Global variables vars: DOMAIN: "dev-core.org" # Inherit libraries libraries: - common ``` -------------------------------- ### Loop with forEach to apply template multiple times Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows how to use loops to apply the same template with different parameters. Each entry in forEach creates an instance with the given NAME and other variables. ```yml # _index.yml applyTemplates: [ api-template ] forEach: # NAME is required for each instance that should be created - NAME: entity-compare-api # You can define other vars as well PORT: 8080 - NAME: favorite-api PORT: 8081 ``` -------------------------------- ### Deploy all apps with octoploy deploy-all Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Deploys all apps defined in the project. ```bash octoploy deploy-all ``` -------------------------------- ### Library definition and usage Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows how to define a library and use it in another project. The library defines required parameters, and the consuming project provides values for those parameters via vars. ```yml # testLib/_root.yml type: library # Required parameters params: - domain - dockerDomain - imageStreamTag ``` ```yml # prod/_root.yml namespace: 'prod-project' libraries: - testLib # Required parameters vars: domain: my-prod.dev-core.org dockerDomain: prod-docker.com imageStreamTag: prod ``` -------------------------------- ### Template file structure before and after Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows the file structure before and after applying a template. The template's dc.yml is injected into the app's directory. ```text |- some-template |- _index.yml |- dc.yml |- my-app |- _index.yml <-- Refers to "some-template" |- others.yml ``` ```text |- my-app |- _index.yml |- others.yml |- dc.yml ``` -------------------------------- ### Merge variables into objects with _merge Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows how to decorate objects using variables and merge them into other objects. The _merge key in deployment.yml merges the someMerging variable, overriding replicas to 2 and adding hello: world. ```yml # _index.yml vars: someMerging: hello: world replicas: 2 ``` ```yml # deployment.yml spec: replicas: 1 _merge: ${someMerging} ``` ```yml spec: replicas: 2 hello: world ``` -------------------------------- ### Define regular variables in _index.yml Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows how to define regular variables in _index.yml. Variables can be referenced in yml files using ${VAR-NAME}. ```yml # _index.yml vars: # Regular key/value assignment key: value ``` -------------------------------- ### Template system class diagram Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows the relationship between Root, App, and Template in the template system. Root provides global variables, Template receives variables and injects yml files into App. ```mermaid classDiagram App <|-- Root: App receives global variables Template <|-- App: Template receives variables Template --|>App: Injects yml files into app class Root{ +variables } class App{ +parameters +k8s yml files } class Template{ +parameters +k8s yml files } ``` -------------------------------- ### Deploy a specific app with octoploy deploy Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Deploys all objects of the app with the given name (e.g., nginx). ```bash octoploy deploy nginx ``` -------------------------------- ### Octoploy folder structure Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows the expected folder structure for an octoploy project. The root config file is _root.yml, and any folder with an _index.yml is considered an app. ```text octoploy |- _root.yml <- Root config, describes the k8s namespace and variables |- my-app <- Any folder with an _index.yml file is considered an app |- _index.yml <- App config |- deployment.yml <- K8s yml file(s) |- secrets.yml Using this structure you could run `octoploy deploy my-app` to deploy all yml files inside the my-app folder. ``` -------------------------------- ### Disable inherited app with enabled: false Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows how to disable a specific app inherited from a library by setting enabled: false in the apps section. ```yaml # prod/_root.yml namespace: 'prod-project' libraries: - testLib apps: # We don't want to use "app1" of the inherited library app1: enabled: false ``` -------------------------------- ### Object merging with nsq-template sidecar Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Shows how object merging works: a template (nsq-template) defines a sidecar container, and when applied to an app via postApplyTemplates, the DeploymentConfig is merged, adding the sidecar container to the app's containers. ```yml # examples/nsq-template/dc.yml kind: Deployment apiVersion: apps/v1 spec: template: spec: containers: - name: "nsqd" image: "nsqio/nsq" ``` ```yml # examples/my-app/dc.yml kind: Deployment apiVersion: apps/v1 metadata: name: "${APP_NAME}" spec: replicas: 1 selector: name: "${APP_NAME}" strategy: type: RollingUpdate template: metadata: labels: name: "${APP_NAME}" spec: containers: - name: "${APP_NAME}" image: "docker-registry.default.svc:5000/oc-project/my-app:prod" ``` ```yml # Merged result after applying template kind: Deployment apiVersion: apps/v1 metadata: name: "${APP_NAME}" spec: replicas: 1 selector: name: "${APP_NAME}" strategy: type: RollingUpdate template: metadata: labels: name: "${APP_NAME}" spec: containers: - name: "${APP_NAME}" image: "docker-registry.default.svc:5000/oc-project/my-app:prod" # This is the part of the template - name: "nsqd" image: "nsqio/nsq" ``` -------------------------------- ### Trigger on-config-change with octoploy reload Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Executes the on-config-change trigger for the specified app (e.g., prometheus). ```bash octoploy reload prometheus ``` -------------------------------- ### File-based configmap definition Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Defines a file-based configmap in _index.yml. Creates a configmap named nginx-config from the file nginx.conf; changes to the file are automatically deployed. ```yml configmaps: - name: nginx-config files: - file: "nginx.conf" ``` -------------------------------- ### Encrypt secrets with octoploy encrypt Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Encrypts a Kubernetes secrets file in place. Requires the OCTOPLOY_KEY environment variable to be set to the encryption key. The file is updated directly. ```bash export OCTOPLOY_KEY="my password" octoploy encrypt secrets.yml ``` -------------------------------- ### Configure value loaders for pem, file, and env sources Source: https://github.com/davidgiga1993/octoploy/blob/main/README.md Defines value loaders in a YAML configuration. The pem loader reads a PEM file and exposes CERT_KEY, CERT_PUBLIC, and CERT_CACERT. The file loader reads a file's content, optionally with encoding (default utf-8) and base64 conversion. The env loader loads environment variables into ENV_*. ```yml vars: # This will load the public/private and intermediate certs # from a pem file and store it in *_KEY, *_PUBLIC, *_CACERT # where * is the key of the value. # In this example: CERT_KEY, CERT_PUBLIC, CERT_CACERT CERT: loader: pem file: my-cert.pem # Load the content of a file into "MY_FILE" MY_FILE: loader: file file: someFile.bin # Optional: Defines in which encoding the file content should be read # utf-8 by default, only applicable if "conversion" is not set. encoding: utf-8 # Optional: Conversion can be used to convert a binary file # into a string representation, in this base base64 conversion: base64 # Load the content of environment variables into ENV_* ENV: loader: env ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.