#Kind cluster with docker socket

1 messages · Page 1 of 1 (latest)

viscid turtle
#

I did it a while ago but never committed it anywhere. I remember that I made it worked. What's you error?

light helm
#

it seems I deleted to error logs. I'll reproduce the error and share log

light helm
#
#12 640.7   [FAILED] in [BeforeAll] - /src/pkg/kubernetes/kubernetes_test.go:40 @ 01/16/23 16:26:13.452
#12 640.7   << Timeline
#12 640.7 
#12 640.7   [FAILED] Expected success, but got an error:
#12 640.7       <*fmt.wrapError | 0xc0006660c0>: {
#12 640.7           msg: "failed to create kind cluster: failed to generate kubeadm config content: failed to get kubernetes version from node: file should only be one line, got 0 lines",
#12 640.7           err: <*errors.withStack | 0xc00118a630>{
#12 640.7               error: <*errors.withMessage | 0xc00118e7c0>{
#12 640.7                   cause: <*errors.withStack | 0xc00118a600>{
#12 640.7                       error: <*errors.withMessage | 0xc00118e7a0>{
#12 640.7                           cause: <*errors.fundamental | 0xc00118a5d0>{
#12 640.7                               msg: "file should only be one line, got 0 lines",
#12 640.7                               stack: [0x22c7037, 0x22c6ffb, 0x22dfb3c, 0x22df8e5, 0x22a0989, 0x110e981],
#12 640.7                           },
#12 640.7                           msg: "failed to get kubernetes version from node",
#12 640.7                       },
#12 640.7                       stack: [0x22dfb99, 0x22dfb9a, 0x22df8e5, 0x22a0989, 0x110e981],
#12 640.7                   },
#12 640.7                   msg: "failed to generate kubeadm config content",
#12 640.7               },
#12 640.7               stack: [0x22dfa65, 0x22dfa66, 0x22a0989, 0x110e981],
#12 640.7           },
#12 640.7       }
#12 640.7       failed to create kind cluster: failed to generate kubeadm config content: failed to get kubernetes version from node: file should only be one line, got 0 lines
#12 640.7   In [BeforeAll] at: /src/pkg/kubernetes/kubernetes_test.go:40 @ 01/16/23 16:26:13.452```
#

I'm getting this error. failed to create kind cluster: failed to generate kubeadm config content: failed to get kubernetes version from node: file should only be one line, got 0 lines" didn't able to understand why I'm getting this error

light helm
#

I just find out when I result of the kind export logs is different based on execution env. if I execute from my local host everything is working however, if I execute command from dagger container. Some contents are missing like kubernetes-version.txt from logs

viscid turtle
#

i dig a little into kind code but it seems it cannot cat /kind/version inside node. but can't find how is it trying to do that

light helm
#

I'm suspecting something blocking docker exec --privileged commands inside of the container

viscid turtle
#

Oh there is a nested privileged argument to dagger withExec. Try setting it to true

light helm
#

I tried but didn't changed the result. I'll try to look more.

light helm
#

interesting, container = container.WithExec([]string{"ash", "-c", "docker exec -t --privileged dagger-engine-8d8bdc86d448fd7b ls"}, dagger.ContainerWithExecOpts{ExperimentalPrivilegedNesting: true}) this is not returning anything to console

#

however, executing same command from my local host returns.

#

note: privileged not change the result of the pipeline

viscid turtle
#

Well, I hand it over to the dagger team, I did reproduce it tough. If I have time I'll look into it

#

<@&946480760016207902>

void cove
#

I can help here. I'll check in ~30m

sand tiger
#

@light helm Is there somewhere we could see the code?

sand tiger
#
    out, err := dg.Container().From("docker:cli").
        WithUnixSocket("/var/run/docker.sock", dg.Host().UnixSocket("/var/run/docker.sock")).
        WithExec([]string{"docker", "ps"}).
        Stdout(ctx)

    if err != nil {
        panic(err)
    }
    fmt.Println(string(out))
#

this works on my machine

novel arrow
#

You may also be hitting the issue described here that required an upstream fix to buildkit: https://github.com/dagger/dagger/issues/4073#issuecomment-1361996260

That problem resulted in output streams from docker containers to be closed early due, which seems to possibly align with the error message of should only be one line, got 0 lines

There is also a follow up fix to that which is going to go into buildkit v0.11.1 (https://github.com/moby/buildkit/pull/3506), last I heard that patch release is coming out today, so once that's out we can update dagger to use the new release and get the fix out

light helm
#

I’m already have docker socket mounted and it’s working

#

I’ll check the upstream issue. That could be related

light helm
#

But docker exec don’t

sand tiger
light helm
#

Tried all combinations, result is same

#

Just try to run a command in a existing container. You should able to replicate the behaviour

#

From my tests, commands using directly docker cli working however if command needs to some kind of forwarding or connections don’t

light helm
sand tiger
#

Indeed.

Ok so I tried to WithExec([]string{"docker", "run", "--rm", "hello-world"}). -- I don't get the output either, but I do see the messages from the docker CLI pulling the image

#

so the docker CLI is exec'ed, and it works -- somehow the container output (and only that) is lost

novel arrow
# sand tiger so the docker CLI is exec'ed, and it works -- somehow the container output (and ...

The context is here: https://github.com/dagger/dagger/issues/4073#issuecomment-1361967787

It has to do with the fact that the docker cli closes the write side of its socket when reading stdout+stderr streams from containers, but then expects to continue reading data. Buildkit's internal mechanisms for proxying sockets didn't handle this correctly though and just closed the whole thing when this happened. I fixed it upstream but we want to wait for v0.11.1, should be soon

sand tiger
#

👍 thanks

#

@light helm In short, docker run / exec does work, however the output doesn't come back. It's a bug upstream which @novel arrow fixed, waiting for the next release

#

As a workaround, using docker run THEN docker logs does the trick for me:

WithExec([]string{"sh", "-c", "docker run --name foo hello-world && docker logs foo"}).

light helm
#

Great news thanks for looking into it.

#

Unfortunately this exec part of the KinD. I just created that snippet for debugging issue

void cove
light helm
#

for reproducing issue running WithExec([]string{"docker", "run", "--rm", "hello-world"}) would be enough. it won't print any output

void cove
light helm
#

same here, I'm surprised as well :). at least we have a fix for it

light helm
#

it seems latest release fixed the kind cluster creation issue. However, networking still has issues. I'll make more test but it seems default kubeconfig trying to reach it from local host and getting timeout

#

I'll make more test and create a gist for the issue

void cove
light helm
#

That's my guess as well, didn't had a chance to look this into more.

sand tiger
# light helm it seems latest release fixed the kind cluster creation issue. However, networki...

Glad that it fixed it!

Regarding the networking issue — @gleaming lance is currently working (and has a working PR) of dagger services / networking! Allows to explicitly define network connections between containers

Perhaps we can see if that helps? Services/networking are meant to start things like a Postgres containers in your pipelines — starting a Kube cluster is a boss level test for this 🙂

gleaming lance
#

yep, I'm starting on container-to-container networking, PR is here: https://github.com/dagger/dagger/pull/4505 - what kind of networking are you trying to do with kind? sounds more like host => container? if so my PR might actually be a step back since it introduces a bridge network, so localhost won't reach ports bound by containers anymore 🤔

swift sentinel
gleaming lance
novel arrow
novel arrow
gleaming lance
light helm
light helm
#

if we can connect two network together, we could use internal kubeconfig to connect cluster easily. However, these are stll assumptions based on docker networks. Not sure if any specifics involved with buildkit

swift sentinel
#

Is there a way to either:

  1. Bring the docker engine inside (run it as a service), then kind can just talk to that

or

  1. Configure kind to not require the docker engine

or

  1. Use something than kind, to run kubernetes entirely inside dagger?
light helm
#

actually we're using some hacky solution run KinD. We're using kind as a lib. Maybe as 4 option we can add custom kind impl as extension. WDYT @swift sentinel ?

#

it would be really neat feature, running a kubernetes cluster with dagger directly.

novel arrow
swift sentinel
#

maybe I’m getting ahead of my skis here, but doen the road assuming we can run kubernetes in dagger directly with privileged containers (plenty of work), could we go even further and have it use a special cri-dagger adapter that runs pods with dagger calls, removing the need for privileged kubelet? 😁

light helm
#

only special thing I can count is multi cluster setups with different network combinations. however, as long as we have access docker socket, we shouldn't have issues

light helm
void cove
#

@light helm aside from the networking thread. Did you manage to make kind the way you needed with the current version of dagger?

#

last thing I recall was that you needed to change kind API server hostname so Dagger can reach to it