Dagger
Search

k3s

Runs a k3s server than can be accessed both locally and in your pipelines

Example
no available example in current language
// starts a k3s server and deploys a helm chart
func (m *Examples) K3S(ctx context.Context) (string, error) {
	k3s := dag.K3S("test")
	kServer := k3s.Server()

	kServer, err := kServer.Start(ctx)
	if err != nil {
		return "", err
	}

	ep, err := kServer.Endpoint(ctx, dagger.ServiceEndpointOpts{Port: 80, Scheme: "http"})
	if err != nil {
		return "", err
	}

	return dag.Container().From("alpine/helm").
		WithExec([]string{"apk", "add", "kubectl"}).
		WithEnvVariable("KUBECONFIG", "/.kube/config").
		WithFile("/.kube/config", k3s.Config()).
		WithExec([]string{"helm", "install", "--wait", "--debug", "nginx", "oci://registry-1.docker.io/bitnamicharts/nginx"}).
		WithExec([]string{"curl", "-sS", ep}).Stdout(ctx)

}
no available example in current language
no available example in current language

Installation

dagger install github.com/tonirvega/daggerverse-1/k3s@a0caf77a1a4782ba6e1383b150780b43e5d5d90c

Entrypoint

Return Type
K3S !
Arguments
NameTypeDescription
nameString !No description provided
imageString No description provided
Example
dagger -m github.com/tonirvega/daggerverse-1/k3s@a0caf77a1a4782ba6e1383b150780b43e5d5d90c call \
 --name string
func (m *myModule) example(name string) *K3S  {
	return dag.
			K3s(name)
}
@function
def example(name: str, ) -> dag.K3S:
	return (
		dag.k3s(name)
	)
@func()
example(name: string, ): K3S {
	return dag
		.k3s(name)
}

Types

K3S 🔗

container() 🔗

Return Type
Container !
Example
dagger -m github.com/tonirvega/daggerverse-1/k3s@a0caf77a1a4782ba6e1383b150780b43e5d5d90c call \
 --name string container
func (m *myModule) example(name string) *Container  {
	return dag.
			K3s(name).
			Container()
}
@function
def example(name: str, ) -> dagger.Container:
	return (
		dag.k3s(name)
		.container()
	)
@func()
example(name: string, ): Container {
	return dag
		.k3s(name)
		.container()
}

server() 🔗

Returns a newly initialized kind cluster

Return Type
Service !
Example
no available example in current language
// starts a k3s server with a local registry and a pre-loaded alpine image
func (m *Examples) K3SServer(ctx context.Context) (*dagger.Service, error) {
	regSvc := dag.Container().From("registry:2.8").
		WithExposedPort(5000).AsService()

	_, err := dag.Container().From("quay.io/skopeo/stable").
		WithServiceBinding("registry", regSvc).
		WithEnvVariable("BUST", time.Now().String()).
		WithExec([]string{"copy", "--dest-tls-verify=false", "docker://docker.io/alpine:latest", "docker://registry:5000/alpine:latest"}, dagger.ContainerWithExecOpts{UseEntrypoint: true}).Sync(ctx)
	if err != nil {
		return nil, err
	}

	return dag.K3S("test").With(func(k *dagger.K3S) *dagger.K3S {
		return k.WithContainer(
			k.Container().
				WithEnvVariable("BUST", time.Now().String()).
				WithExec([]string{"sh", "-c", `
cat <<EOF > /etc/rancher/k3s/registries.yaml
mirrors:
  "registry:5000":
    endpoint:
      - "http://registry:5000"
EOF`}).
				WithServiceBinding("registry", regSvc),
		)
	}).Server(), nil
}
no available example in current language
no available example in current language

withContainer() 🔗

Returns a newly initialized kind cluster

Return Type
K3S !
Arguments
NameTypeDefault ValueDescription
cContainer !-No description provided
Example
dagger -m github.com/tonirvega/daggerverse-1/k3s@a0caf77a1a4782ba6e1383b150780b43e5d5d90c call \
 --name string with-container --c IMAGE:TAG
func (m *myModule) example(name string, c *Container) *K3S  {
	return dag.
			K3s(name).
			WithContainer(c)
}
@function
def example(name: str, c: dagger.Container) -> dag.K3S:
	return (
		dag.k3s(name)
		.with_container(c)
	)
@func()
example(name: string, c: Container): K3S {
	return dag
		.k3s(name)
		.withContainer(c)
}

config() 🔗

returns the config file for the k3s cluster

Return Type
File !
Arguments
NameTypeDefault ValueDescription
localBoolean falseNo description provided
Example
dagger -m github.com/tonirvega/daggerverse-1/k3s@a0caf77a1a4782ba6e1383b150780b43e5d5d90c call \
 --name string config
func (m *myModule) example(name string) *File  {
	return dag.
			K3s(name).
			Config()
}
@function
def example(name: str, ) -> dagger.File:
	return (
		dag.k3s(name)
		.config()
	)
@func()
example(name: string, ): File {
	return dag
		.k3s(name)
		.config()
}

kubectl() 🔗

runs kubectl on the target k3s cluster

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
argsString !-No description provided
Example
no available example in current language
// returns a kubectl container with the configured kube config context ready to run
// administrative commands
func (m *Examples) K3SKubectl(ctx context.Context, args string) *dagger.Container {
	return dag.K3S("test").Kubectl(args)
}
no available example in current language
no available example in current language

kns() 🔗

runs k9s on the target k3s cluster

Return Type
Container !
Example
dagger -m github.com/tonirvega/daggerverse-1/k3s@a0caf77a1a4782ba6e1383b150780b43e5d5d90c call \
 --name string kns
func (m *myModule) example(name string) *Container  {
	return dag.
			K3s(name).
			Kns()
}
@function
def example(name: str, ) -> dagger.Container:
	return (
		dag.k3s(name)
		.kns()
	)
@func()
example(name: string, ): Container {
	return dag
		.k3s(name)
		.kns()
}