Kubectl::CLIWrapper - Module to use the Kubernetes API via the kubectl CLI
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
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/.
kubectl
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
kubectl options
By default initialized to kubectl. It will try to find kubectl in the PATH. You can set it explicitly to specific kubectl excecutable.
Path to your kube configuration, defaults to $HOME/.kube/config via kubectl.
$HOME/.kube/config
The URL of the Kubernetes service
The username for Basic Authentication
The password for Basic Authentication
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
A Boolean flag that tells kubectl to not verify the certificate of the server it connects to
The Kubernetes namespace to operate in.
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.
output
success
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.
'-o=json'
json
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.
https://kubernetes.io/docs/tasks/tools/install-kubectl/
IO::K8s
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/
Net::Kubernetes
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
Jose Luis Martinez CAPSiDE jlmartinez@capside.com
The source code is located here: https://github.com/pplu/kubectl-cliwrapper
Please report bugs to: https://github.com/pplu/kubectl-cliwrapper/issues
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.
To install Kubectl::CLIWrapper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Kubectl::CLIWrapper
CPAN shell
perl -MCPAN -e shell install Kubectl::CLIWrapper
For more information on module installation, please visit the detailed CPAN module installation guide.