The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Kubectl::CLIWrapper - Module to use the Kubernetes API via the kubectl CLI

SYNOPSIS

use Kubectl::CLIWrapper;

my $kube = Kubectl::CLIWrapper->new(
  server => 'https://kubernetes.example.org/',
  username => 'user',
  password => 'pass',
);

my $result = $kube->run('explain', 'service');
# $result->success == 1 if the command executed correctly
# $result->output contains the output of the command

my $result = $kube->json('get', 'pods');
# $result->success == 1 if the command executed correctly
# $result->output contains the output of the command
# $result->json is a hashref with the result of the parsed JSON output of the command

my $result = $kube->input('{"kind":"Service" ... }', 'create', '-f', '-');
# $result->success == 1 if the command executed correctly
# $result->output contains the output of the command 

DESCRIPTION

This module helps you use the Kubernetes API. It sends all it's commands via the CLI command line tool kubectl. You can find kubectl installation instructions here https://kubernetes.io/docs/tasks/tools/install-kubectl/.

CREDENTIALS

Kubectl::CLIWrapper attributes are mainly the options you can pass kubectl to control how it authenticates to the Kubernetes server. Run kubectl options to discover what these options do. If you don't initialize any attributes, kubectl will behave just like on the command line (loading ~/.kube/config) which may be already set to point to a Kubernetes server

ATTRIBUTES

kubectl

By default initialized to kubectl. It will try to find kubectl in the PATH. You can set it explicitly to specific kubectl excecutable.

kubeconfig

Path to your kube configuration, defaults to $HOME/.kube/config via kubectl.

server

The URL of the Kubernetes service

username

The username for Basic Authentication

password

The password for Basic Authentication

token

The Bearer token for authentication. If it's a scalar, that value will be used. If it's a coderef (sub {}), it will be invoked each time kubectl is called and it's return value used as the value of the --token option

insecure_tls

A Boolean flag that tells kubectl to not verify the certificate of the server it connects to

namespace

The Kubernetes namespace to operate in.

METHODS

run(@parameters)

Will run kubectl with the parameters. Returns a Kubectl::CLIWrapper::Result object with output set to the output of the command, and success a Boolean to indicate if the command reported successful execution.

json(@parameters)

Will run kubectl with the parameters, and '-o=json'. Returns a Kubectl::CLIWrapper::Result object with output set to the output of the command, and json set to a hashref with the parsed JSON. success will be false if JSON parsing fails.

input($input_to_kubectl, @parameters)

Will run kubectl with the parametes, sending $input_to_kubectl on it's STDIN. Returns a Kubectl::CLIWrapper::Result object with output set to the output of the command. success will be set accordingly.

SEE ALSO

https://kubernetes.io/docs/tasks/tools/install-kubectl/

IO::K8s

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/

Net::Kubernetes

CONTRIBUTORS

waterkip: - adding the possiblity to set a kubeconfig file - helping port to Moose

ureesoriano: - fix for token attribute being ignored - dynamic generation of the "token" command-line option

AUTHOR

Jose Luis Martinez
CAPSiDE
jlmartinez@capside.com

BUGS and SOURCE

The source code is located here: https://github.com/pplu/kubectl-cliwrapper

Please report bugs to: https://github.com/pplu/kubectl-cliwrapper/issues

COPYRIGHT and LICENSE

Copyright (c) 2018 by CAPSiDE This code is distributed under the Apache 2 License. The full text of the license can be found in the LICENSE file included with this module.