Package: kubedeployer
kubedeployerRUDeploy application on Kubernetes.Key FeaturesDeploy application using manifests.Deploy application using kustomize.Manifests can contain environment variables.Contain security scanner for Kubernetes resources.Contain security scanner for docker images.Contain dry-run mode, where only the manifest is built without applying it.Installationusing pipusing dockerUsing pippipinstallkubedeployerUsing dockerdockerrunitlabsio/kubedeployerHow to builddockerbuild\--build-argVAULT_URL=<host-to-vault>\--build-argVAULT_APPROLE_ID=<vault-approle-id>\--build-argVAULT_APPROLE_SECRET=<vault-approle-secret>\--build-argVAULT_SECRETS_PREFIX=<vault-secret-prefix>\-tkubedeployer\-fDockerfile.VAULT_URL- Vault URL.VAULT_APPROLE_ID- the approle id allows machines or apps to
authenticate with Vault-defined roles.VAULT_APPROLE_SECRET- approle secret.VAULT_SECRETS_PREFIX- template of vault-path to secret where store
connection settings to Kubernetes (ex.: template/to/cluster/*/secret).UsagekubedeployoptionsExamplekubedeploy-dorthodox--dry-run--env-file./base.txt./production.txtOptions-d,-deployer=smart: structure maintenance types
(see Supported structure maintenance types);--dry-run: only show built manifest without apply it;--env-filelist: read in a file of environment variables. If environment
variable does contain in several files, then it will be has value from last file.--project-dir <path>: full path to folder with project, if it is not setted,
used value from environment variableCI_PROJECT_DIR, if variable is not setted, as
default value used current working directory--environment <env_name>: environment for builder, if it is not setted, used
value from environment variableENVIRONMENT--manifest-folder <path>: path to folder with manifest, path is relative to project_dir. If it is not set, will get value from environment variableMANIFEST_FOLDERSupported structure maintenance typesKubedeployer supports three structure maintenance types of manifests to deploy:orthodoxsmart - this one is defaultkustomizeEach deployer is responding for collecting and processing manifest filesOrthodoxCollecting filesFind yaml-files inMANIFEST_FOLDER;Append files from subdirectory with nameENVIRONMENT.Processing filesReplace placeholder like${VAR_NAME}by corresponding environment variablesVAR_NAMEin found files
from previous step;Concatenate all files in one.SmartSmart deployer has different behavior depending on presence of thekustomization.yamlfile
inMANIFEST_FOLDERxorMANIFEST_FOLDER/ENVIRONMENT:it has not been foundit has been foundKustomization.yaml has NOT been foundCollecting filesWork like orthodox deployerProcessing filesCreatekustomization.yamlwith all collected yaml-files;Replace placeholder like orthodox deployerCreate resulting manifest bykustomize buildKustomization.yaml has been foundCollecting filesIt does not collect files because they all are listed inkustomization.yamlProcessing filesCreate resulting manifest bykustomize buildReplace placeholder like orthodox deployer in resulting manifestIf you want to have quoted values after replacing placeholders like"123"not123, you should to make double quotes around the placeholder
like'"${PLACEHOLDER}"'because of specific of working kustomizeKustomizeIf inMANIFEST_FOLDERwere foundkustomization.yamlfile then deployer will collect files by kustomize.
Deploy happens by applyingkustomization.yamlUnlike previous deployers this one does not replace placeholders and do not try to guess what can be deployed.How to launch in gitlab-ci.ymldeploy:stage:deployimage:kubedeployerenvironment:name:developmentvariables:KUBE_URL:$KUBERNETES_URLKUBE_TOKEN:$KUBERNETES_TOKENKUBE_NAMESPACE:$KUBERNETES_NAMESPACEENVIRONMENT:$APPLICATION_ENVIRONMENTMANIFEST_FOLDER:./manifestsscript:-kubedeployscript has options to choose deployer type (orthodox, smart and kustomize). Default value is orthodox.
Example:deploy:script:-kubedeploy -d smartEnvironmentsRequired# Kubernetes URL where need to deploy application.KUBE_URL:"https://kube.local"# Directory inside project where manifests are located.MANIFEST_FOLDER:"./manifests"Additional# If the KUBECONFIG environment variable does exist, kubectl uses an effective# configuration that is the result of merging the files listed in the KUBECONFIG# environment variable.KUBECONFIG:"${HOME}/.kube/config"# Kubernetes access token.KUBE_TOKEN:"ey3423423423dfeg34gr34..."# Kubernetes namespace where application will be deployed by default if# namespace not set in manifests.KUBE_NAMESPACE:"default"# Environments describe where code is deployed (ex.: stage, production, ..).ENVIRONMENT:"development"# Show manifests that will be applied.SHOW_MANIFESTS:"False"# Template that allows filtering docker image names for Trivy report.TRIVY_IMAGE_TEMPLATE:"registry\.example\.com"How it worksKubedeployer collect directories inside which manifests will be found. Root
directory are set with variableMANIFEST_FOLDER, also to use extended
searching need to set value in variableENVIRONMENT. For example:└── applications
    └── manifests
        ├── development
        │   ├── configurations
        │   │   └── cm.yaml
        │   └── ingress.yaml
        ├── deployment.yaml
        └── svc.yaml
        
I. Found directories if MANIFEST_FOLDER set only:

    MANIFEST_FOLDER = ./manifests
    
    ./manifests

II. Found directories if MANIFEST_FOLDER and ENVIRONMENT are set
    (in current case subdirectory `production` does not  exist):

    MANIFEST_FOLDER = ./manifests
    ENVIRONMENT = production
    
    ./manifests

III. Found directories if MANIFEST_FOLDER and ENVIRONMENT are set:

    MANIFEST_FOLDER = ./manifests
    ENVIRONMENT = development

    ./manifests
    ./manifests/development
    ./manifests/development/configurationsThere are next variants when Kubedeployer was foundkustomization.yamlin
getting directories:kustomization.yamlsuccessfully found.If Kubedeployer found multiplekustomization.yamlfiles then will throw
exception. To fix it you are need set path to directory inMANIFEST_FOLDERthat contain requiredkustomization.yaml.Kubedeployer auto createkustomization.yamlinMANIFEST_FOLERif it
can't find it.Examples:Project without kustomization.yaml└── applications
    └── manifests
        ├── development
        │   ├── cm.yaml
        │   └── ingress.yaml
        ├── production
        │   ├── cm.yaml
        │   └── ingress.yaml
        ├── deployment.yaml
        └── svc.yaml

MANIFEST_FOLDER = ./manifests
ENVIRONMENT = development

Kubedeployer will create kustomization.yaml with content:

./manifests/kustomization.yaml
    resources:
    - ./manifests/deployment.yaml
    - ./manifests/svc.yaml
    - ./manifests/development/cm.yaml
    - ./manifests/development/ingress.yamlProject with kustomization.yaml└── applications
    └── manifests
        ├── base
        │   ├── kustomization.yaml
        │   ├── development.yaml
        │   └── svc.yaml
        └── overlays
            ├── development
            │   ├── kustomization.yaml
            │   ├── cm.yaml
            │   └── ingress.yaml
            └── production
                ├── kustomization.yaml
                ├── cm.yaml
                └── ingress.yaml

MANIFEST_FOLDER = ./manifests/overlays/development

In our case, Kubedeployer will use the following file:
    ./manifests/overlays/development/kustomization.yamlProject contains error└── applications
    └── manifests
        ├── development
        │   ├── kustomization.yaml
        │   ├── ingress.yaml
        │   └── configurations
        │       ├── kustomization.yaml
        │       └── cm.yaml
        ├── kustomization.yaml
        ├── deployment.yaml
        └── svc.yaml

MANIFEST_FOLDER = ./manifests
ENVIRONMENT = development

Kubedeployer will throw an exception after found multiple files:
    - ./manifests/kustomization.yaml
    - ./manifests/development/kustomization.yaml
    - ./manifests/development/configurations/kustomization.yaml