### Install Kanister Tools (kanctl and kando) Source: https://docs.kanister.io/tooling Installation of the Kanister CLI tools, `kanctl` and `kando`, requires Go to be installed on the system. A provided bash script automates the download and installation process for both tools. ```bash # The script installs both kanctl and kando $ curl https://raw.githubusercontent.com/kanisterio/kanister/master/scripts/get.sh | bash ``` -------------------------------- ### KubeExec Blueprint Phase Example (YAML) Source: https://docs.kanister.io/functions A YAML example demonstrating how to configure a Blueprint phase to use the KubeExec function. It shows how to pass arguments like namespace, pod, container, and command using Go templating. ```yaml - func: KubeExec name: examplePhase args: namespace: "{{ .Deployment.Namespace }}" pod: "{{ index .Deployment.Pods 0 }}" container: kanister-sidecar command: - sh - -c - | echo "Example" ``` -------------------------------- ### KubeExecAll Blueprint Phase Example (YAML) Source: https://docs.kanister.io/functions A YAML configuration for a Blueprint phase using KubeExecAll. This example demonstrates passing multiple pods and containers, along with the command to be executed in parallel across them. ```yaml - func: KubeExecAll name: examplePhase args: namespace: "{{ .Deployment.Namespace }}" pods: "{{ index .Deployment.Pods 0 }} {{ index .Deployment.Pods 1 }}" containers: "container1 container2" command: - sh - -c - | echo "Example" ``` -------------------------------- ### ActionSet Example Configuration (YAML) Source: https://docs.kanister.io/architecture Provides an example of how to configure an ActionSet in YAML format. This snippet demonstrates the structure for defining actions, including their names, blueprints, target objects, and profiles. It serves as a practical reference for creating ActionSets. ```yaml spec: actions: - name: example-action blueprint: example-blueprint object: kind: Deployment name: example-deployment namespace: example-namespace profile: apiVersion: v1alpha1 kind: profile name: example-profile namespace: example-namespace ``` -------------------------------- ### KubeExec Command Example (Bash) Source: https://docs.kanister.io/functions Illustrates how to use the KubeExec function, which is analogous to running `kubectl exec`. It details the arguments required for specifying the namespace, pod, container, and the command to execute. ```bash kubectl exec -it --namespace -c [CMD LIST...] ``` -------------------------------- ### KubeTask Blueprint Phase Example (YAML) Source: https://docs.kanister.io/functions An example of a Blueprint phase using the KubeTask function to spin up a new Pod for executing a command. It shows how to specify the image, command, and optional overrides for pod specifications, annotations, and labels. ```yaml - func: KubeTask name: examplePhase args: namespace: "{{ .Deployment.Namespace }}" image: busybox podOverride: serviceAccountName: containers: - name: container imagePullPolicy: IfNotPresent podAnnotations: annKey: annValue podLabels: labelKey: labelValue command: - sh - -c - | echo "Example" ``` -------------------------------- ### ActionSet with Pod Labels and Annotations Configuration Source: https://docs.kanister.io/tutorial An ActionSet example demonstrating how to apply custom labels and annotations to pods created by Kanister functions. These configurations are applied to all pods spawned by the specified action. ```yaml $ cat <> /var/log/time.log; sleep 1; done; truncate /var/log/time.log --size 0; done"] EOF ``` -------------------------------- ### List Kanister Helm Chart Values Source: https://docs.kanister.io/install Displays the configurable values for the Kanister Helm chart. This command is useful for understanding and customizing the Kanister installation, such as specifying image tags or other parameters. ```bash helm show values kanister/kanister-operator ``` -------------------------------- ### Install Grafana with Loki Data Source Source: https://docs.kanister.io/tasks/logs Installs Grafana using Helm, pre-configuring it with a Loki data source. It dynamically retrieves the Loki service URL and uses a heredoc to pass the Grafana configuration, including the Loki data source details, to the Helm installation command. ```bash svc_url=$(kubectl -n loki get svc loki -ojsonpath='{.metadata.name}.{.metadata.namespace}:{.spec.ports[?(@.name=="http-metrics")].port}') cat < ``` -------------------------------- ### Go Time Templating Example Source: https://docs.kanister.io/templates Shows how to use Go's templating engine with the sprig date functions to format the current time, provided as a RFC3339Nano string, into a desired precision and format. ```go // Example using sprig date template functions to format time. // Assumes '.Time' is a variable containing the current time in RFC3339Nano format. "{{ toDate "2006-01-02T15:04:05.999999999Z07:00" .Time | date "3:04PM" }}" ``` -------------------------------- ### ScaleWorkload: Scale Kubernetes Workloads (Bash Example) Source: https://docs.kanister.io/functions Demonstrates scaling a Kubernetes deployment using kubectl, which ScaleWorkload abstracts. This command-line approach is useful for understanding the underlying operations of the ScaleWorkload function. ```bash kubectl scale deployment --replicas= --namespace ``` -------------------------------- ### Kanctl Create Backup ActionSet Example Source: https://docs.kanister.io/tooling Demonstrates how to create a new backup ActionSet using `kanctl create actionset`. It requires specifying the action, namespace, blueprint, deployment, and profile. The output confirms the creation of the ActionSet. ```bash # Action name and blueprint are required $ kanctl create actionset --action backup --namespace kanister --blueprint time-log-bp \ --deployment kanister/time-logger \ --profile s3-profile actionset backup-9gtmp created # View the progress of the ActionSet $ kubectl --namespace kanister describe actionset backup-9gtmp ``` -------------------------------- ### Verify Kanister Workloads Source: https://docs.kanister.io/install Checks the status of pods in the 'kanister' namespace to confirm that the Kanister operator is running. This is a crucial step after installation to ensure the operator is healthy. ```bash kubectl -n kanister get po ``` -------------------------------- ### Kanister Profile Templating Examples Source: https://docs.kanister.io/templates Illustrates how to access S3 bucket information and associated credentials from a Kanister Profile using Go templating within a Blueprint. Assumes a specific credential structure. ```yaml # Access the Profile s3 location bucket "{{ .Profile.Location.Bucket }}" # Access the associated secret credential # Assuming "{{ .Profile.Credential.KeyPair.SecretField }}" is 'Secret' "{{ .Profile.Credential.KeyPair.Secret }}" ``` -------------------------------- ### Create ConfigMap for S3 Backup Location Source: https://docs.kanister.io/tutorial Creates a Kubernetes ConfigMap named 's3-location' in the 'kanister' namespace. This ConfigMap stores the S3 path where data will be backed up. Users should replace the example bucket path with their accessible path. ```yaml apiVersion: v1 kind: ConfigMap metadata: name: s3-location namespace: kanister data: path: s3://time-log-test-bucket/tutorial ``` -------------------------------- ### Example Kanister Profile and Secret Definition (YAML) Source: https://docs.kanister.io/architecture Provides an example YAML definition for a Kanister Profile, including location, credential, and SSL verification settings, along with a corresponding Kubernetes Secret. ```yaml apiVersion: cr.kanister.io/v1alpha1 kind: Profile metadata: name: example-profile namespace: example-namespace location: type: s3Compliant bucket: example-bucket endpoint: : prefix: "" region: "" credential: type: keyPair keyPair: idField: example_key_id secretField: example_secret_access_key secret: apiVersion: v1 kind: Secret name: example-secret namespace: example-namespace skipSSLVerify: true --- apiVersion: v1 kind: Secret type: Opaque metadata: name: example-secret namespace: example-namespace data: example_key_id: example_secret_access_key: ``` -------------------------------- ### Get Kanister ActionSet Status Source: https://docs.kanister.io/tutorial Retrieves the status of all Kanister ActionSets in the 'kanister' namespace in YAML format. This command helps in monitoring the execution status of Kanister actions. ```bash kubectl --namespace kanister get actionsets.cr.kanister.io -o yaml ``` -------------------------------- ### Install Promtail to Stream Logs to Loki Source: https://docs.kanister.io/tasks/logs Installs Promtail, a log shipping agent, using Helm. It configures Promtail to send logs to the Loki instance by specifying the Loki push endpoint URL. The command also confirms the successful rollout of the Promtail DaemonSet. ```bash svc_url=$(kubectl -n loki get svc loki -ojsonpath='{.metadata.name}.{.metadata.namespace}:{.spec.ports[?(@.name=="http-metrics")].port}') helm -n loki upgrade --install --create-namespace promtail grafana/promtail \ --set image.tag=2.5.0 \ --set "config.clients[0].url=http://${svc_url}/loki/api/v1/push" ``` -------------------------------- ### Specify Pod Name using Options in Kanister ActionSet Source: https://docs.kanister.io/templates Demonstrates how to use the 'Options' map in a Kanister ActionSet to specify a particular Pod for executing actions. This allows for fine-grained control over where Blueprint actions are performed. The 'podName' option is used here as an example. ```yaml apiVersion: cr.kanister.io/v1alpha1 kind: ActionSet metadata: generateName: s3backup- namespace: kanister spec: actions: - name: backup blueprint: my-blueprint object: kind: deployment name: my-deployment namespace: default options: podName: some-pod ``` -------------------------------- ### Access DeploymentConfig Name in Template (Go) Source: https://docs.kanister.io/templates Example of accessing the `Name` field of a DeploymentConfig using Kanister's templating syntax. This demonstrates referencing a field within the `DeploymentConfigParams` struct. ```go "{{ index .DeploymentConfig.Name }}" ``` -------------------------------- ### Kanctl Create Restore ActionSet Example Source: https://docs.kanister.io/tooling Illustrates creating a restore ActionSet from a previously created backup ActionSet using `kanctl create actionset --action restore --from `. This command allows overriding parameters from the parent ActionSet if needed. ```bash # If necessary you can override the secrets, profile, config-maps, options etc obtained from the parent ActionSet $ kanctl create actionset --action restore --from backup-9gtmp --namespace kanister actionset restore-backup-9gtmp-4p6mc created ``` -------------------------------- ### Create S3 Compliant Profile Source: https://docs.kanister.io/tooling This section explains how to create a new S3-compliant profile using the `kanctl create profile s3compliant` command. It outlines the necessary flags such as bucket name, access key, secret key, region, and endpoint. The example shows a successful creation, resulting in a new secret and profile. ```bash $ kanctl create profile s3compliant --bucket --access-key ${AWS_ACCESS_KEY_ID} \ --secret-key ${AWS_SECRET_ACCESS_KEY} \ --region us-west-1 \ --namespace kanister secret 's3-secret-chst2' created profile 's3-profile-5mmkj' created ``` -------------------------------- ### Install Kanister with Custom Certificates Source: https://docs.kanister.io/install Installs Kanister using custom TLS certificates for the validating webhook server. This involves specifying the custom certificate mode, providing the CA bundle, and referencing the TLS secret. ```bash helm upgrade --install kanister kanister/kanister-operator --namespace kanister --create-namespace \ --set bpValidatingWebhook.tls.mode=custom \ --set bpValidatingWebhook.tls.caBundle=$(cat /path/to/ca.pem | base64 -w 0) \ --set bpValidatingWebhook.tls.secretName=tls-secret ``` -------------------------------- ### Install Kanister with CRDs Disabled Source: https://docs.kanister.io/install Installs Kanister while disabling the automatic management and update of Custom Resource Definitions (CRDs) by the operator. This is useful if you prefer to manage CRDs manually or through a separate process. Helm will manage the CRDs in this configuration. ```bash helm -n kanister upgrade \ --install kanister \ --create-namespace kanister/kanister-operator \ --set controller.updateCRDs=false ``` -------------------------------- ### Add Kanister Helm Repository Source: https://docs.kanister.io/install Adds the Kanister Helm chart repository to your local Helm configuration. This command requires Helm to be installed and configured. ```bash helm repo add kanister https://charts.kanister.io/ ``` -------------------------------- ### Kanctl Create Command Help Source: https://docs.kanister.io/tooling Displays help information for the 'kanctl create' command, outlining its subcommands and global flags. It shows how to create ActionSets, Profiles, and Kopia repository servers. ```bash $ kanctl create --help Create a custom kanister resource Usage: kanctl create [command] Available Commands: actionset Create a new ActionSet or override a ActionSet profile Create a new profile repository-server Create a new kopia repository server Flags: --dry-run if set, resource YAML will be printed but not created -h, --help help for create --skip-validation if set, resource is not validated before creation Global Flags: -n, --namespace string Override namespace obtained from kubectl context Use "kanctl create [command] --help" for more information about a command. ``` -------------------------------- ### Create Kanister ActionSet for Backup Source: https://docs.kanister.io/tutorial Creates a Kanister ActionSet named 's3backup-' in the 'kanister' namespace. This ActionSet triggers the 'backup' action defined in the 'time-log-bp' Blueprint, targeting the 'time-logger' Deployment in the 'default' namespace. ```bash cat < ActionSet Usage: kanctl create actionset [flags] Flags: -a, --action string action for the action set (required if creating a new action set) -b, --blueprint string blueprint for the action set (required if creating a new action set) -c, --config-maps strings config maps for the action set, comma separated ref=namespace/name pairs (eg: --config-maps ref1=namespace1/name1,ref2=namespace2/name2) -d, --deployment strings deployment for the action set, comma separated namespace/name pairs (eg: --deployment namespace1/name1,namespace2/name2) -f, --from string specify name of the action set -h, --help help for actionset -k, --kind string resource kind to apply selector on. Used along with the selector specified using --selector/-l (default "all") -T, --namespacetargets strings namespaces for the action set, comma separated list of namespaces (eg: --namespacetargets namespace1,namespace2) -O, --objects strings objects for the action set, comma separated list of object references (eg: --objects group/version/resource/namespace1/name1,group/version/resource/namespace2/name2) -o, --options strings specify options for the action set, comma separated key=value pairs (eg: --options key1=value1,key2=value2) -p, --profile string profile for the action set -v, --pvc strings pvc for the action set, comma separated namespace/name pairs (eg: --pvc namespace1/name1,namespace2/name2) -s, --secrets strings secrets for the action set, comma separated ref=namespace/name pairs (eg: --secrets ref1=namespace1/name1,ref2=namespace2/name2) -l, --selector string k8s selector for objects --selector-namespace string namespace to apply selector on. Used along with the selector specified using --selector/-l -t, --statefulset strings statefulset for the action set, comma separated namespace/name pairs (eg: --statefulset namespace1/name1,namespace2/name2) Global Flags: --dry-run if set, resource YAML will be printed but not created -n, --namespace string Override namespace obtained from kubectl context --skip-validation if set, resource is not validated before creation ``` -------------------------------- ### Launch and Verify Argo Cron Workflow Source: https://docs.kanister.io/tasks/argo Commands to create a cron workflow, list existing cron workflows, and check for the creation of Kanister ActionSets. This helps in confirming the successful deployment and initial execution of the scheduled workflow. ```bash argo cron create mysql-cron-wf.yaml -n argo argo cron list -n argo kubectl get actionsets.cr.kanister.io -n kanister ``` -------------------------------- ### Access PVC Name in Template (Go) Source: https://docs.kanister.io/templates Example of accessing the `Name` field of a PVC using Kanister's templating syntax. This demonstrates referencing the `Name` field within the `PVCParams` struct. ```go "{{ .PVC.Name }}" ``` -------------------------------- ### Define Kanister Blueprint for Backup and Restore Source: https://docs.kanister.io/tutorial This YAML defines a Kanister Blueprint for the `time-log-bp`. It includes two actions: `backup` to copy a log file to S3 and `restore` to copy it back. The `backup` action uses a ConfigMap for the S3 path, while the `restore` action uses an input artifact (`timeLog`) containing the S3 path. ```yaml cat <complete Normal Ended Phase 19s Kanister Controller Completed phase backupToS3 ``` -------------------------------- ### Create TLS Secret for Webhook Source: https://docs.kanister.io/install Creates a Kubernetes TLS secret to store custom certificates for the Kanister validating admission webhook server. This secret is required when using custom certificates instead of the auto-generated self-signed ones. ```bash kubectl create secret tls my-tls-secret \--cert /path/to/tls.crt \--key /path/to/tls.key -n kanister ``` -------------------------------- ### Create ActionSet with Dry Run Source: https://docs.kanister.io/tooling This command demonstrates how to create an ActionSet for a backup operation using the `kanctl create actionset` command with the `--dry-run` flag. It specifies the action, namespace, blueprint, selectors, kind, and profile. The output shows the generated ActionSet YAML without actually creating the resource. ```bash $ kanctl create actionset --action backup --namespace kanister --blueprint time-log-bp \ --selector app=time-logger \ --kind deployment \ --selector-namespace kanister \ --profile s3-profile \ --dry-run apiVersion: cr.kanister.io/v1alpha1 kind: ActionSet metadata: creationTimestamp: null generateName: backup- spec: actions: - blueprint: time-log-bp configMaps: {} name: backup object: apiVersion: "" kind: deployment name: time-logger namespace: kanister options: {} profile: apiVersion: "" kind: "" name: s3-profile namespace: kanister secrets: {} ``` -------------------------------- ### Deploy Argo Workflows Minimal Manifest Source: https://docs.kanister.io/tasks/argo Applies the minimal manifest file to deploy Argo Workflows CRDs and essential resources into the 'argo' namespace. This is a quick way to set up Argo for basic usage. ```bash kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-workflows/master/manifests/quick-start-minimal.yaml -n argo ``` -------------------------------- ### Access First Pod of StatefulSet in Template (Go) Source: https://docs.kanister.io/templates Example of accessing the name of the first pod within a StatefulSet using Kanister's templating syntax. This demonstrates how to reference fields within the `StatefulSetParams` struct. ```go "{{ index .StatefulSet.Pods 0 }}" ``` -------------------------------- ### Accessing Options in Kanister Blueprints (Go Templating) Source: https://docs.kanister.io/templates Shows how to access parameters defined in the 'Options' map within Kanister Blueprints using Go templating. This enables dynamic configuration of actions based on provided options. ```go "{{ .Options.podName }}" ``` -------------------------------- ### Dry Run ActionSet Creation with Kanctl Source: https://docs.kanister.io/tooling Preview the YAML configuration of an ActionSet without actually creating it by using the `--dry-run` flag with `kanctl create actionset`. This is helpful for verifying the ActionSet configuration before execution. ```bash The --dry-run flag will print the YAML of the ActionSet without actually creating it. bash ``` -------------------------------- ### Kanister Function Go Interface Definition Source: https://docs.kanister.io/functions Defines the Go interface that all Kanister Functions must implement. This includes methods for getting the function's name, executing the function's logic, and specifying required and supported arguments. ```go package kanister import ( "context" ) // Func allows custom actions to be executed. type Func interface { Name() string Exec(ctx context.Context, args ...string) (map[string]interface{}, error) RequiredArgs() []string Arguments() []string } ``` -------------------------------- ### Query All Kanister Logs in Grafana Source: https://docs.kanister.io/tasks/logs This LogQL query is used in Grafana's Log Browser to retrieve all logs associated with the 'kanister' namespace. It's a basic filter to start exploring log data. ```logql {namespace="kanister"} ``` -------------------------------- ### Describe Kanister Blueprint Source: https://docs.kanister.io/tutorial Retrieves detailed information about the 'time-log-bp' Kanister Blueprint in the 'kanister' namespace, including its events. This command is useful for verifying the Blueprint's creation and status. ```bash kubectl --namespace kanister describe Blueprint time-log-bp ``` -------------------------------- ### Add Kanister Tools to Dockerfile using curl Source: https://docs.kanister.io/tooling This snippet demonstrates how to add Kanister tools to your custom Docker image. It uses `curl` to download a script from a GitHub repository and pipes it to `bash` for execution. Ensure you have `curl` installed in your base image. ```dockerfile RUN curl https://raw.githubusercontent.com/kanister/kanister/master/scripts/get.sh | bash ``` -------------------------------- ### Referencing Phase Output in Kanister Blueprints (Go Templating) Source: https://docs.kanister.io/templates Illustrates how to reference output artifacts from a specific phase in Kanister Blueprints using Go templating. This allows subsequent phases or actions to consume data produced by earlier phases. ```go "{{ .Phases.phase-name.Output.key-name }}" ``` -------------------------------- ### Create Custom Role for Kanister (YAML) Source: https://docs.kanister.io/rbac This YAML defines a custom Role named 'kanister-role' within the application's namespace. It specifies granular permissions, including access to pods, PVCs, secrets, deployments, and statefulsets, with 'get', 'list', and 'watch' verbs. ```yaml apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: kanister-role namespace: rules: - apiGroups: [""] resources: ["pods", "pods/log", "persistentvolumeclaims", "secrets"] verbs: ["get", "list", "watch"] - apiGroups: ["apps"] resources: ["deployments", "statefulsets"] verbs: ["get", "list", "watch"] ``` -------------------------------- ### Set Kanister Log Level to Debug using Helm Source: https://docs.kanister.io/tasks/logs_level This command demonstrates how to set the Kanister logging level to 'debug' when deploying or upgrading using Helm. It targets the 'kanister/kanister-operator' chart and uses the `controller.logLevel` variable for configuration. Ensure you have Helm installed and configured to interact with your Kubernetes cluster. ```bash helm -n kanister upgrade --install kanister \ --set controller.logLevel=debug \ --create-namespace kanister/kanister-operator ```