kubectl
The goal of this module is to be the one stop shop for interacting with akubernetes cluster. The main challenge when doing this is how authentication
is done against the cluster. Eventually this module should support all most
used methods.
Each top level method is in charge of creating a container with all the tools
and credentials ready to go for kubectl commands to be executed. For an example on how this is implemented you can check out the `KubectlEks` method.
Example (CreatePod)
no available example in current language
// Get the logs of a pod from a deployment using the deployment name
func (m *Examples) Kubectl_CreatePod(ctx context.Context, kubeConfig, awsCreds *dagger.Secret, awsProfile string) (string, error) {
k := dag.Kubectl(kubeConfig).
KubectlEks(awsCreds, awsProfile)
// use `k` to get the list of pods from a deployment, getting only the pod
// name as output
out, err := k.Exec(ctx, []string{"get", "pods", "-n", "kube-system", "-o", "jsonpath='{.items[0].metadata.name}'"})
if err != nil {
return "", err
}
// return the logs for the pod that was fetched
return k.Exec(ctx, []string{"logs", "-n", "kube-system", out})
}
no available example in current language
no available example in current language
Installation
dagger install github.com/anarcher/matipan-daggerverse/kubectl@6a4174b3c62ac47f14fd6e1ae3e592c1a9cb0823
Entrypoint
Return Type
Kubectl !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
kubeconfig | Secret ! | - | No description provided |
Example
dagger -m github.com/anarcher/matipan-daggerverse/kubectl@6a4174b3c62ac47f14fd6e1ae3e592c1a9cb0823 call \
--kubeconfig env:MYSECRET
func (m *myModule) example(kubeconfig *dagger.Secret) *dagger.Kubectl {
return dag.
Kubectl(kubeconfig)
}
@function
def example(kubeconfig: dagger.Secret) -> dagger.Kubectl:
return (
dag.kubectl(kubeconfig)
)
@func()
example(kubeconfig: Secret): Kubectl {
return dag
.kubectl(kubeconfig)
}
Types
Kubectl 🔗
kubeconfig() 🔗
Return Type
Secret !
Example
dagger -m github.com/anarcher/matipan-daggerverse/kubectl@6a4174b3c62ac47f14fd6e1ae3e592c1a9cb0823 call \
--kubeconfig env:MYSECRET kubeconfig
func (m *myModule) example(kubeconfig *dagger.Secret) *dagger.Secret {
return dag.
Kubectl(kubeconfig).
Kubeconfig()
}
@function
def example(kubeconfig: dagger.Secret) -> dagger.Secret:
return (
dag.kubectl(kubeconfig)
.kubeconfig()
)
@func()
example(kubeconfig: Secret): Secret {
return dag
.kubectl(kubeconfig)
.kubeconfig()
}
kubectlEks() 🔗
KubectlEks returns a KubectlCLI with aws-iam-authenticator and AWS credentials configured to communicate with an EKS cluster.
Return Type
Cli !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
awsConfig | Secret | - | No description provided |
awsCreds | Secret ! | - | No description provided |
awsProfile | String ! | - | No description provided |
Example
no available example in current language
// Returns a container that echoes whatever string argument is provided
func (m *Examples) KubectlKubectlEks(ctx context.Context, kubeConfig, awsCreds *dagger.Secret, awsProfile string) (string, error) {
k := dag.Kubectl(kubeConfig).
KubectlEks(awsCreds, awsProfile)
return k.
Exec(ctx, []string{"get", "pods", "-n", "kube-system"})
}
no available example in current language
no available example in current language
Cli 🔗
KubectlCLI is a child module that holds a Container that should already be configured to talk to a k8s cluster.
container() 🔗
Return Type
Container !
Example
dagger -m github.com/anarcher/matipan-daggerverse/kubectl@6a4174b3c62ac47f14fd6e1ae3e592c1a9cb0823 call \
kubectl-eks --aws-creds env:MYSECRET --aws-profile string \
container
func (m *myModule) example(awsCreds *dagger.Secret, awsProfile string) *dagger.Container {
return dag.
Kubectl().
KubectlEks(awsCreds, awsProfile).
Container()
}
@function
def example(aws_creds: dagger.Secret, aws_profile: str) -> dagger.Container:
return (
dag.kubectl()
.kubectl_eks(aws_creds, aws_profile)
.container()
)
@func()
example(awsCreds: Secret, awsProfile: string): Container {
return dag
.kubectl()
.kubectlEks(awsCreds, awsProfile)
.container()
}
exec() 🔗
Exec runs the specified kubectl command.
NOTE: kubectl
should be specified as part of the cmd variable.
For example, to list pods: [“get”, “pods”, “-n”, “namespace”]
Return Type
String !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
cmd | [String ! ] ! | - | No description provided |
Example
dagger -m github.com/anarcher/matipan-daggerverse/kubectl@6a4174b3c62ac47f14fd6e1ae3e592c1a9cb0823 call \
kubectl-eks --aws-creds env:MYSECRET --aws-profile string \
exec --cmd string1 --cmd string2
func (m *myModule) example(ctx context.Context, awsCreds *dagger.Secret, awsProfile string, cmd []string) string {
return dag.
Kubectl().
KubectlEks(awsCreds, awsProfile).
Exec(ctx, cmd)
}
@function
async def example(aws_creds: dagger.Secret, aws_profile: str, cmd: List[str]) -> str:
return await (
dag.kubectl()
.kubectl_eks(aws_creds, aws_profile)
.exec(cmd)
)
@func()
async example(awsCreds: Secret, awsProfile: string, cmd: string[]): Promise<string> {
return dag
.kubectl()
.kubectlEks(awsCreds, awsProfile)
.exec(cmd)
}
debugSh() 🔗
DebugSh is a helper function that developers can use to get a terminal into the container where the commands are run and troubleshoot potential misconfigurations. For example: dagger call –kubeconfig kubeconfig.yaml kubectl-eks –aws-creds ~/.aws/credentials –aws-profile “example” –aws-config ~/.aws/config debug-sh terminal
Return Type
Container !
Example
dagger -m github.com/anarcher/matipan-daggerverse/kubectl@6a4174b3c62ac47f14fd6e1ae3e592c1a9cb0823 call \
kubectl-eks --aws-creds env:MYSECRET --aws-profile string \
debug-sh
func (m *myModule) example(awsCreds *dagger.Secret, awsProfile string) *dagger.Container {
return dag.
Kubectl().
KubectlEks(awsCreds, awsProfile).
DebugSh()
}
@function
def example(aws_creds: dagger.Secret, aws_profile: str) -> dagger.Container:
return (
dag.kubectl()
.kubectl_eks(aws_creds, aws_profile)
.debug_sh()
)
@func()
example(awsCreds: Secret, awsProfile: string): Container {
return dag
.kubectl()
.kubectlEks(awsCreds, awsProfile)
.debugSh()
}