Skip to main content

kubectl CLI reference

ModularPipelines.Kubernetes provides strongly typed access to the kubectl CLI.

Executable prerequisite​

This package does not install the kubectl executable. Install it separately and ensure kubectl is available on PATH.

Follow the executable's official documentation for installation instructions.

Package installation​

dotnet add package ModularPipelines.Kubernetes

Resolve the service with context.Tools.Kubernetes. Projects using C# 13 or another .NET language can use context.Tools.Get<ModularPipelines.Kubernetes.Services.IKubernetes>() instead.

Module example​

using ModularPipelines;
using ModularPipelines.Kubernetes.Enums;
using ModularPipelines.Kubernetes.Options;

public class RunCommandModule : Module<CommandResult>
{
protected override async Task<CommandResult> ExecuteAsync(
IModuleContext context,
CancellationToken cancellationToken)
{
return await context.Tools.Kubernetes.Config.ViewAsync(
new KubernetesConfigViewOptions(),
cancellationToken: cancellationToken);
}
}

Global options​

Global options are rendered after the selected subcommand.

CLI optionPropertyAvailabilityDescription
--asAsAll editionsUsername to impersonate for the operation. User could be a regular user or a service account in a namespace.
--as-groupAsGroupAll editionsGroup to impersonate for the operation, this flag can be repeated to specify multiple groups.
--as-uidAsUidAll editionsUID to impersonate for the operation.
--as-user-extraAsUserExtraAll editionsUser extras to impersonate for the operation, this flag can be repeated to specify multiple values for the same key.
--cache-dirCacheDirAll editionsDefault cache directory.
--certificate-authorityCertificateAuthorityAll editionsPath to a cert file for the certificate authority
--client-certificateClientCertificateAll editionsPath to a client certificate file for TLS
--client-keyClientKeyAll editionsPath to a client key file for TLS
--clusterClusterAll editionsThe name of the kubeconfig cluster to use
--contextContextAll editionsThe name of the kubeconfig context to use
--disable-compressionDisableCompressionAll editionsIf true, opt-out of response compression for all requests to the server
--insecure-skip-tls-verifyInsecureSkipTlsVerifyAll editionsIf true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--kubeconfigKubeConfigAll editionsPath to the kubeconfig file to use for CLI requests.
--kubercKubercAll editionsPath to the kuberc file to use for preferences. This can be disabled by exporting KUBECTL_KUBERC=false feature gate or turning off the feature KUBERC=off.
--log-flush-frequencyLogFlushFrequencyAll editionsMaximum number of seconds between log flushes
--match-server-versionMatchServerVersionAll editionsRequire server version to match client version
--namespaceNamespaceAll editionsIf present, the namespace scope for this CLI request
--passwordPasswordAll editionsPassword for basic authentication to the API server
--profileProfileAll editionsName of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex|trace)
--profile-outputProfileOutputAll editionsName of the file to write the profile to
--proxy-urlProxyUrlAll editionsProxy URL to use for requests to the API server
--request-timeoutRequestTimeoutAll editionsThe length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.
--serverServerAll editionsThe address and port of the Kubernetes API server
--tls-server-nameTlsServerNameAll editionsServer name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
--tokenTokenAll editionsBearer token for authentication to the API server
--userUserAll editionsThe name of the kubeconfig user to use
--usernameUsernameAll editionsUsername for basic authentication to the API server
--vVAll editionsnumber for the log level verbosity
--vmoduleVmoduleAll editionscomma-separated list of pattern=N settings for file-filtered logging (only works for the default text log format)
--warnings-as-errorsWarningsAsErrorsAll editionsTreat warnings received from the server as errors and exit with a non-zero exit code

Commands​

CLI commandOptions record
kubectl annotateKubernetesAnnotateOptions
kubectl applyKubernetesApplyOptions
kubectl apply edit-last-appliedKubernetesApplyEditLastAppliedOptions
kubectl apply set-last-appliedKubernetesApplySetLastAppliedOptions
kubectl apply view-last-appliedKubernetesApplyViewLastAppliedOptions
kubectl attachKubernetesAttachOptions
kubectl authKubernetesAuthOptions
kubectl auth can-iKubernetesAuthCanIOptions
kubectl auth reconcileKubernetesAuthReconcileOptions
kubectl auth whoamiKubernetesAuthWhoamiOptions
kubectl autoscaleKubernetesAutoscaleOptions
kubectl certificateKubernetesCertificateOptions
kubectl certificate approveKubernetesCertificateApproveOptions
kubectl certificate denyKubernetesCertificateDenyOptions
kubectl cluster-infoKubernetesClusterInfoOptions
kubectl cluster-info dumpKubernetesClusterInfoDumpOptions
kubectl configKubernetesConfigOptions
kubectl config delete-clusterKubernetesConfigDeleteClusterOptions
kubectl config delete-contextKubernetesConfigDeleteContextOptions
kubectl config delete-userKubernetesConfigDeleteUserOptions
kubectl config get-contextsKubernetesConfigGetContextsOptions
kubectl config rename-contextKubernetesConfigRenameContextOptions
kubectl config setKubernetesConfigSetOptions
kubectl config set-clusterKubernetesConfigSetClusterOptions
kubectl config set-contextKubernetesConfigSetContextOptions
kubectl config set-credentialsKubernetesConfigSetCredentialsOptions
kubectl config unsetKubernetesConfigUnsetOptions
kubectl config use-contextKubernetesConfigUseContextOptions
kubectl config viewKubernetesConfigViewOptions
kubectl cordonKubernetesCordonOptions
kubectl cpKubernetesCpOptions
kubectl debugKubernetesDebugOptions
kubectl describeKubernetesDescribeOptions
kubectl diffKubernetesDiffOptions
kubectl drainKubernetesDrainOptions
kubectl eventsKubernetesEventsOptions
kubectl execKubernetesExecOptions
kubectl kubercKubernetesKubercOptions
kubectl kuberc setKubernetesKubercSetOptions
kubectl kuberc viewKubernetesKubercViewOptions
kubectl labelKubernetesLabelOptions
kubectl logsKubernetesLogsOptions
kubectl patchKubernetesPatchOptions
kubectl port-forwardKubernetesPortForwardOptions
kubectl proxyKubernetesProxyOptions
kubectl replaceKubernetesReplaceOptions
kubectl rolloutKubernetesRolloutOptions
kubectl rollout historyKubernetesRolloutHistoryOptions
kubectl rollout pauseKubernetesRolloutPauseOptions
kubectl rollout restartKubernetesRolloutRestartOptions
kubectl rollout resumeKubernetesRolloutResumeOptions
kubectl rollout statusKubernetesRolloutStatusOptions
kubectl rollout undoKubernetesRolloutUndoOptions
kubectl scaleKubernetesScaleOptions
kubectl taintKubernetesTaintOptions
kubectl topKubernetesTopOptions
kubectl top nodeKubernetesTopNodeOptions
kubectl top podKubernetesTopPodOptions
kubectl uncordonKubernetesUncordonOptions
kubectl versionKubernetesVersionOptions
kubectl waitKubernetesWaitOptions