Closed omer-bar closed 1 year ago
it seems like that the image was not loaded to your k3d cluster,
could you try to configure a afterhook stanza under your build in your skaffold.yaml , something similar to this
apiVersion: skaffold/v4beta1
kind: Config
build:
artifacts:
- image: skaffold-example
hooks:
after:
- command:
- "bash"
- "-c"
- "k3d image import --cluster /your/cluster/name $SKAFFOLD_IMAGE"
this will load your image to your cluster after skaffold build
tried what you were suggesting, still cant pull the image
apiVersion: skaffold/v4beta2
kind: Config
build:
artifacts:
- image: skaffold-example
hooks:
after:
- command:
- "bash"
- "-c"
- "sudo k3s ctr images import ./skaffold-example.tar"
manifests:
rawYaml:
- k8s-pod.yaml
somewhere in the creation of the deployments stage on the k3s cluster it just fails to pull the image... Also tried a bunch of stuff to make it work, added a imagePullSecret to the depl with the docker hub credentials, before and after hooks with the built image, put every way of auth into k3s for a bunch of registries(quay, docker hub, ghcr etc) on every node... pretty much made sure that whatever is skaffold or k3s tries to do with external and internal services - they can.
@EryX666 ~can you try to replace - "sudo k3s ctr images import ./skaffold-example.tar"
with sudo k3s ctr images import $SKAFFOLD_IMAGE
~
Skaffold inject the built image reference into $SKAFFOLD_IMAGE env variable so post hook on the host machine can use it .. more info can be found here.
https://skaffold.dev/docs/pipeline-stages/lifecycle-hooks/#environment-variables
Also, could you double check the imagePollPolicy in your manifest .. should set to Never or IfNotPresent so your cluster doesn't need to fetch image from remote if your image is available on cluster nodes.
Finally got this works on my machine, due to skaffold use docker image id as tag to identify image for deployment in local dev.. the previous suggestion doesn't work.. so we need to do some trick to get the correct image id for deployment . could you try something like below ?
kind: Config
build:
artifacts:
- image: skaffold-example
hooks:
after:
- command:
- "bash"
- "-c"
- docker save skaffold-example:$(docker inspect --format="{{slice .Id 7}}" $SKAFFOLD_IMAGE) | sudo k3s ctr images import -
local:
push: false
manifests:
rawYaml:
- k8s-pod.yaml
I have to specify the kubeconfig for k3s cluster.. if you also need to do this, please see the following example command for dev
skaffold dev --kubeconfig /etc/rancher/k3s/k3s.yaml --cache-artifacts=false
I also disabled cache just to make sure build post hook is always triggered
You can also start a local registry with docker then use it as default registry with skaffold
Example command:
docker run -d -p 5000:5000 registry:2
skaffold dev --kubeconfig /etc/rancher/k3s/k3s.yaml --cache-artifacts=false --default-repo=localhost:5000
ok yha it worker, problem now is, for some reason my personal project doesnt tail logs from the containers, but the getting-started does so... i dont know why exactly this happens... the project does tail the logs on windows docker-desktop cluster and on linux docker-desktop cluster just not in k3s for some reason.
i want to preface something first - on my own machine i have k3s and i have one project who i finally got to work with skaffold just to find out the containers aren't tailing as they should, so i wanted to know maybe its a problem with k3s because on docker-desktop "built-in" cluster the tailing works, opened a fresh VM and took the steps to reproduce the behavior in the title(hence the maybe? no trailing of containers, i cant even pull images with examples to find out if its consistent with k3s or just a problem on my end)
Expected behavior
the images should be pulled and there should be tailing of the container
Actual behavior
images aren't pulling and no tail when they are being pulled
Information
Steps to reproduce the behavior
skaffold dev -vdebug log in nodejs example: