NAME

Kubernetes::REST::Kubeconfig - Parse kubeconfig files and create Kubernetes::REST instances

VERSION

version 1.100

SYNOPSIS

use Kubernetes::REST::Kubeconfig;

# Use default kubeconfig and current context
my $kc = Kubernetes::REST::Kubeconfig->new;
my $api = $kc->api;

# Specify kubeconfig and context
my $kc = Kubernetes::REST::Kubeconfig->new(
    kubeconfig_path => '/path/to/kubeconfig',
    context_name => 'my-cluster',
);

# List available contexts
my $contexts = $kc->contexts;

# Get API for specific context
my $api = $kc->api('production');

# Inside a Kubernetes pod: no kubeconfig needed, auto-detects service account
my $api = Kubernetes::REST::Kubeconfig->new->api;

DESCRIPTION

Parses Kubernetes kubeconfig files (typically ~/.kube/config) and creates configured Kubernetes::REST instances.

When no kubeconfig file is found, automatically falls back to in-cluster authentication using the pod's service account token.

Supports:

  • Multiple clusters and contexts

  • Token authentication

  • Client certificate authentication

  • Inline certificate data (base64 encoded)

  • External certificate files

  • Exec-based credential plugins

  • In-cluster service account auto-detection

kubeconfig_path

Path to the kubeconfig file. Defaults to ~/.kube/config.

context_name

Optional. The context name to use. If not specified, uses the current-context from the kubeconfig.

current_context_name

my $name = $kc->current_context_name;

Returns the current context name (either from context_name attribute or from the kubeconfig's current-context).

contexts

my $contexts = $kc->contexts;

Returns an arrayref of all available context names from the kubeconfig.

api

my $api = $kc->api;
my $api = $kc->api('production');

Create a Kubernetes::REST instance configured from the kubeconfig. If $context_name is provided, uses that context; otherwise uses the current context.

Falls back to in-cluster service account authentication when no kubeconfig file is found and the pod has a mounted token at /var/run/secrets/kubernetes.io/serviceaccount/token.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/pplu/kubernetes-rest/issues.

IRC

Join #kubernetes on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHORS

  • Torsten Raudssus <torsten@raudssus.de>

  • Jose Luis Martinez Torres <jlmartin@cpan.org> (JLMARTIN, original author, inactive)

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019 by Jose Luis Martinez.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004