kubectl-1.7.0

KOSI Plugin Kubectl Version 1.7.0

Summary

The kubectl plugin allows to interact with Kubernetes clusters by executing kubectl commands within a KOSI package. This plugin provides a convenient way to manage Kubernetes resources, retrieve information and execute administrative tasks directly within a KOSI package. It supports various kubectl operations, including retrieving, creating, updating, and deleting Kubernetes resources.

The plugin integrates seamlessly with Kubernetes by supporting all official resource types and their associated subcommands. Additionally, it allows users to save command outputs as variables or files and provides the option to execute commands with elevated privileges using sudo.

Keys

Key Required Description
operation Yes Specifies the kubectl subcommand to execute, such as get, apply, delete, etc.
resource Yes (for most operations) Defines the type of Kubernetes resource being operated on (e.g., pod, service, deployment).
resourceName Optional Specifies the name(s) of the resource(s) to target. Names are case-sensitive. If omitted, the command applies to all resources of the given type.
flags Optional Additional flags for the kubectl command. If using -f, an absolute file path must be provided. Multiple flags should be separated by spaces. Example: "-f /path/to/file.yaml -A -o wide".
verb Optional Specifies an additional action supported by Kubernetes, such as can-i for checking permissions. Used in combination with relevant operations.
outputVar Optional Stores the command output in a variable for use in subsequent operations within the KOSI package.
outputFile Optional Saves the output of the command to a specified absolute file path.
sudo Optional Set to true to execute the command with sudo privileges.
sudoPassword Yes (if sudo is enabled) Specifies the password required for sudo execution.

Notes:

  • Ensure that the Kubernetes cluster is accessible from the system where KOSI is running.
  • When using sudo, ensure the correct password is provided, or configure NOPASSWD for the executing user in the system’s sudoers file.
  • The plugin supports all standard Kubernetes resources and their associated operations.
  • Use outputVar or outputFile to capture command outputs for further processing.

Examples

Example 1 - Retrieving Information About a Specific Pod

This example retrieves details about a specific pod called testDeployment in the kube-system namespace. The output is stored in a variable and saved to a file.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-package";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files =
{
    input = "template.yaml";
}

install
{
    kubectl
    (
        operation = "get";
        resource = "pods";
        resourceName = "testDeployment";
        flags = "-n kube-system -o wide";
        outputVar = "outputGet";
        outputFile = "/root/outputKubectlGet.txt";
        sudo = "true";
        sudoPassword = "Drowssap";
    );
}

Example 2 - Checking User Permissions

This example checks whether the current user has permission to list pods in the cluster using the can-i command.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-package";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files =
{
  input = "template.yaml";
}

install
{
    kubectl
    (
        operation = "auth";
        verb = "can-i";
        flags = "list pods";
        outputVar = "permissionCheck";
    );
}

Example 3 - Applying a Configuration File

This example applies a Kubernetes manifest file located at /home/user/deployment.yaml.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-package";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files =
{
    input = "template.yaml";
}

install
{
    kubectl
    (
        operation = "apply";
        flags = "-f /home/user/deployment.yaml";
    );
}

Example 4 - Deleting Multiple Pods

This example deletes two specific pods named example-pod1 and example-pod2 with sudo privileges.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-package";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files =
{
    input = "template.yaml";
}

install
{
    kubectl
    (
        operation = "delete";
        resource = "pod";
        resourceName = "example-pod1 example-pod2";
        sudo = "true";
        sudoPassword = "Drowssap";
    );
}

Example 5 - Saving Output to a File

This example retrieves a list of all services and saves the output to a file at /var/log/kubectl_services.log.

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-package";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files =
{
    input = "template.yaml";
}

install
{
    kubectl
    (
        operation = "get";
        resource = "services";
        flags = "-A";
        outputFile = "/var/log/kubectl_services.log";
    );
}