pia-2.2.0

Required license: KOSI Enterprise

KOSI Plugin PIA Version 2.2.0

Summary

The PIA plugin (Plugin-based Infrastructure Administrator) is designed to automate administrative tasks in Kubernetes clusters by enabling remote command execution and file transfers. It currently only operates in ssh mode:

  • SSH Mode: Executes commands and transfers files via SSH, requiring a specified user with appropriate permissions.

This plugin simplifies managing multiple nodes, making it useful for executing system configurations, software deployments, and maintenance tasks across a cluster.

Keys

Key Required Description
mode Yes Defines how PIA operates. Possible value: ssh.
nodes Yes (or only labels) Specifies target nodes where commands should be executed. Either nodes or labels must be set.
labels Yes (or only nodes) Defines node selection via labels instead of explicit node names. Either nodes or labels must be set.
files Optional Lists files to be uploaded before executing the command. Files in ssh mode are uploaded to PIAROOT, located at KUBEOPSROOT/pia.
command Yes Specifies the command to be executed on the target nodes.
user Yes Defines the user for SSH connections. Typically requires root privileges.

Notes:

  • The default path for KUBEOPSROOT is /var/kubeops - in this case the PIAROOT is in /var/kubeops/pia.

Examples

Example 1 - SSH Mode

In this example, the PIA plugin transfers template.yaml to specified nodes and executes a command under the root user.

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";
}

containers =
{
    example = ["docker.io", "nginx", "latest"];
}

install
{
    pia
    (
        mode = "ssh";
        nodes = "['cluster2master1', 'cluster2master2']";
        files = "['template.yaml']";
        command = "echo Hello World";
        user = "root";
    );
}

Expected Behavior

  • The template.yaml file is uploaded to PIAROOT, located at KUBEOPSROOT/pia on cluster2master1 and cluster2master2.
  • The command echo Hello World is executed on each node using SSH.
  • The connection is established under the root user.

Recommendation: The specified user should have root privileges to execute administrative commands effectively.

Example 2 - Using PIA Plugin with other plugins

Using pia with the osCheck, if and print plugins

This example shows the interaction of several plugins. In this example, we use the pia plugin together with the osCheck, if and print plugins to check whether it is the correct operating system and to output a specific message and execute a corresponding PIA operation with the pia plugin:

languageversion = "1.0.0";
apiversion = "kubernative/kubeops/sina/user/v4";
name = "kosi-example-pia-oscheck-if-print";
description = "Example using pia with oscheck and if and print";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files = 
{
    inputRhel = "rhel9.yaml";
    inputOtherOS = "otherOs.yaml";
}

install
{
    osCheck(getOSVar = "os"; getOSVersionVar = "version");

    if (condition = "$os$ = 'Red Hat Enterprise Linux'") then
    {
        print(message = "Performing PIA operation for RHEL 9..");
        pia
        (
            mode = "ssh";
            nodes = "['cluster2master1']";
            files = "['rhel9.yaml']";
            command = "echo Hello RHEL 9";
            user = "rhel9User";
        );
    }
    else
    {
        print(message = "Other OS recognized instead of RHEL 9, performing alternative PIA operation..");
        pia
        (
            mode = "ssh";
            nodes = "['cluster2master1']";
            files = "['otherOs.yaml']";
            command = "echo Hello other OS";
            user = "otherUser";
        );
    }
}

Expected Behavior

If os is Red Hat Enterprise Linux:

2025-02-26 15:18:28 Info:      Performing PIA operation for RHEL 9..
  • The rhel8.yaml file is uploaded to cluster2master1.
  • The command echo Hello RHEL 9 is executed on each node using SSH.
  • The connection is established under the rhel8User user.

Otherwise:

2025-02-26 15:18:28 Info:      Other OS recognized instead of RHEL 9, performing alternative PIA operation..
  • The otherOs.yaml file is uploaded to cluster2master1.
  • The command echo Hello other OS is executed on each node using SSH.
  • The connection is established under the otherUser user.