.. _kubernetes.core.kubeconfig_module:
**************************
kubernetes.core.kubeconfig
**************************
**Generate, update, and optionally write Kubernetes kubeconfig files**
Version added: 6.5.0
.. contents::
:local:
:depth: 1
Synopsis
--------
- Build, update, and manage Kubernetes kubeconfig files using structured input.
- Supports loading an existing kubeconfig file and merging clusters, users, and contexts.
- Can optionally write the resulting kubeconfig to a destination path.
- Ensures idempotent behavior by only updating files when changes occur.
Requirements
------------
The below requirements are needed on the host that executes this module.
- PyYAML >= 5.1
Parameters
----------
.. raw:: html
| Parameter |
Choices/Defaults |
Comments |
|
clusters
list
/ elements=dictionary
|
Default:
[]
|
List of cluster definitions to merge into the kubeconfig.
Each cluster is identified by its name.
When name matches an existing cluster, the default behavior is V(merge).
See the behavior suboption for V(replace), V(keep), and V(remove).
|
|
behavior
string
|
Choices:
merge ←
- replace
- keep
- remove
|
How to handle merging if a cluster with this name already exists.
merge - Update only the specified fields, preserve others (default).
replace - Replace the entire cluster definition.
keep - Keep existing cluster, skip this entry.
remove - Remove the cluster entry entirely. Silently skipped if the entry does not exist.
|
|
cluster
dictionary
|
|
Cluster configuration details.
Not required when behavior is V(remove).
|
|
|
certificate-authority
string
|
|
Path to a CA certificate file for validating the API server certificate.
|
|
|
certificate-authority-data
string
|
|
Base64 encoded CA certificate data.
Use this instead of certificate-authority for embedded certificates.
|
|
|
insecure-skip-tls-verify
boolean
|
|
If true, the server's certificate will not be validated.
|
|
|
proxy-url
string
|
|
Optional proxy URL for cluster connections.
|
|
|
server
string
/ required
|
|
Kubernetes API server URL (e.g., https://k8s.example.com:6443).
|
|
|
tls-server-name
string
|
|
Server name to use for server certificate validation.
|
|
name
string
/ required
|
|
Unique name identifier for the cluster.
|
|
contexts
list
/ elements=dictionary
|
Default:
[]
|
List of context definitions linking users and clusters.
Each context is identified by its name.
When name matches an existing context, the default behavior is V(merge).
See the behavior suboption for V(replace), V(keep), and V(remove).
|
|
behavior
string
|
Choices:
merge ←
- replace
- keep
- remove
|
How to handle merging if a context with this name already exists.
merge - Update only the specified fields, preserve others (default).
replace - Replace the entire context definition.
keep - Keep existing context, skip this entry.
remove - Remove the context entry entirely. Silently skipped if the entry does not exist.
|
|
context
dictionary
|
|
Context configuration linking cluster and user.
Not required when behavior is V(remove).
|
|
|
cluster
string
/ required
|
|
Name of the cluster to use (must match a cluster name in O(clusters)).
|
|
|
namespace
string
|
|
Default namespace to use for this context.
If not specified, defaults to default.
|
|
|
user
string
/ required
|
|
Name of the user to authenticate as (must match a user name in O(users)).
|
|
name
string
/ required
|
|
Unique name identifier for the context.
|
|
current_context
string
|
|
Name of the context to set as current/active.
This context will be used by default when using kubectl.
Must match one of the context names defined in O(contexts).
|
|
dest
string
|
|
Destination path where the final kubeconfig should be written.
If not specified, the kubeconfig will be saved to O(path).
Allows copying and modifying a kubeconfig to a new location.
|
|
path
string
/ required
|
|
Path to an existing kubeconfig file to load and merge from.
If the file does not exist, a new kubeconfig will be created.
This becomes the default destination if O(dest) is not specified.
|
|
preferences
dictionary
|
Default:
{}
|
Kubeconfig preferences.
Used for client-side settings like color output, default editor, etc.
|
|
users
list
/ elements=dictionary
|
Default:
[]
|
List of user authentication configurations.
Each user is identified by its name.
When name matches an existing user, the default behavior is V(merge).
See the behavior suboption for V(replace), V(keep), and V(remove).
|
|
behavior
string
|
Choices:
merge ←
- replace
- keep
- remove
|
How to handle merging if a user with this name already exists.
merge - Update only the specified fields, preserve others (default).
replace - Replace the entire user definition.
keep - Keep existing user, skip this entry.
remove - Remove the user entry entirely. Silently skipped if the entry does not exist.
|
|
name
string
/ required
|
|
Unique name identifier for the user.
|
|
user
dictionary
|
|
User authentication configuration.
Not required when behavior is V(remove).
|
|
|
auth-provider
dictionary
|
|
Authentication provider configuration (e.g., for GCP, Azure).
|
|
|
client-certificate
string
|
|
Path to client certificate file.
Used for certificate-based authentication.
|
|
|
client-certificate-data
string
|
|
Base64 encoded client certificate.
Use instead of client-certificate for embedded certificates.
|
|
|
client-key
string
|
|
Path to client private key file.
Must be provided with client-certificate.
|
|
|
client-key-data
string
|
|
Base64 encoded client private key.
Use instead of client-key for embedded keys.
|
|
|
exec
dictionary
|
|
Exec-based credential plugin configuration.
Used for external authentication providers.
|
|
|
password
string
|
|
Password for basic authentication.
|
|
|
token
string
|
|
Bearer token for authentication.
|
|
|
username
string
|
|
Username for basic authentication.
|