loft-sh / vcluster

vCluster - Create fully functional virtual Kubernetes clusters - Each vcluster runs inside a namespace of the underlying k8s cluster. It's cheaper than creating separate full-blown clusters and it offers better multi-tenancy and isolation than regular namespaces.
https://www.vcluster.com
Apache License 2.0
6.16k stars 373 forks source link

`devspace run dev` fails with "error: unauthorized:" while pushing image #644

Closed guettli closed 1 year ago

guettli commented 1 year ago

What happened?

I want to set up the develoment environment with devspace for the first time.

I followed the text in CONRIBUTING.md

vcluster on  main via 🐹 v1.18.2 took 33s 
❯ minikube start -p vhost
😄  [vhost] minikube v1.25.2 auf Ubuntu 21.10
✨  Verwende den Treiber docker basierend auf dem existierenden Profil
👍  Starte Control Plane Node vhost in Cluster vhost
🚜  Ziehe das Base Image ...
🏃  Aktualisiere den laufenden docker "vhost" container ...
🐳  Vorbereiten von Kubernetes v1.23.3 auf Docker 20.10.12...
    ▪ kubelet.housekeeping-interval=5m
🔎  Verifiziere Kubernetes Komponenten...
    ▪ Verwende Image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Addons aktiviert: storage-provisioner, default-storageclass
🏄  Fertig! kubectl ist jetzt für die standardmäßige (default) Verwendung des Clusters "vhost und des Namespaces "default" konfiguriert
vcluster on  main via 🐹 v1.18.2 took 2s 
❯ kubectl create -f ./hack/wrong-cluster-ip-service.yaml 
The Service "service-simple-service" is invalid: spec.clusterIPs: Invalid value: []string{"1.1.1.1"}: failed to allocate IP 1.1.1.1: the provided IP (1.1.1.1) is not in the valid range. The range of valid IPs is 10.96.0.0/12

vcluster on  main via 🐹 v1.18.2 
❯ export SERVICE_CIDR=10.96.0.0/12
vcluster on  main via 🐹 v1.18.2 
❯ devspace run dev
[info]   Using namespace 'vcluster'
[info]   Using kube context 'vhost'
[info]   Rebuild image  because tag is missing                      
[info]   Building image 'ghcr.io/loft-sh/loft-enterprise/dev-vcluster:PNusiDI' with engine 'buildkit'
[info]   Execute BuildKit command with: docker buildx build --tag ghcr.io/loft-sh/loft-enterprise/dev-vcluster:PNusiDI --push --file Dockerfile --target builder -
[+] Building 0.3s (0/1)                                                                                                       
[+] Building 98.6s (19/19) FINISHED                                                                                           
 => [internal] load remote build context                                                                                 0.4s
 => copy /context /                                                                                                      0.3s
 => [internal] load metadata for docker.io/library/golang:1.18                                                           1.7s
 => [builder  1/14] FROM docker.io/library/golang:1.18@sha256:1bbb02af44e5324a6eabe502b6a928d368977225c0255bc9aca4a734  51.7s
 => => resolve docker.io/library/golang:1.18@sha256:1bbb02af44e5324a6eabe502b6a928d368977225c0255bc9aca4a734145f86e1     0.0s
...
 => [builder  2/14] WORKDIR /vcluster-dev                                                                                0.5s
 => [builder  3/14] RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.goo  7.1s
 => [builder  4/14] RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 &  3.4s
 => [builder  5/14] RUN if [ "amd64" = "amd64" ]; then go install github.com/go-delve/delve/cmd/dlv@latest; fi           6.8s 
 => [builder  6/14] COPY go.mod go.mod                                                                                   0.0s 
 => [builder  7/14] COPY go.sum go.sum                                                                                   0.0s 
 => [builder  8/14] COPY vendor/ vendor/                                                                                 0.4s 
 => [builder  9/14] COPY cmd/vcluster cmd/vcluster                                                                       0.0s 
 => [builder 10/14] COPY cmd/vclusterctl cmd/vclusterctl                                                                 0.0s
 => [builder 11/14] COPY pkg/ pkg/                                                                                       0.0s
 => [builder 12/14] RUN ln -s "$(pwd)/manifests" /manifests                                                              0.2s
 => [builder 13/14] RUN mkdir -p /.cache /.config                                                                        0.3s
 => [builder 14/14] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -mod vendor -o /vcluster cmd/vcl  22.6s
 => exporting to image                                                                                                   2.3s
 => => exporting layers                                                                                                  2.3s
 => => writing image sha256:0fd25d4d5632d80d19b36f1a8c09bb275fde614da7dfe71ed8069a96a227759e                             0.0s
 => => naming to ghcr.io/loft-sh/loft-enterprise/dev-vcluster:PNusiDI                                                    0.0s
 => ERROR pushing ghcr.io/loft-sh/loft-enterprise/dev-vcluster:PNusiDI with docker                                       0.5s
 => => pushing layer f1ab699f4105                                                                                        0.4s
...
------
 > pushing ghcr.io/loft-sh/loft-enterprise/dev-vcluster:PNusiDI with docker:
------
error: unauthorized: unauthenticated: User cannot be authenticated with the token provided.
[fatal]  error building image ghcr.io/loft-sh/loft-enterprise/dev-vcluster:PNusiDI: exit status 1

What did you expect to happen?

I expected

DevSpace UI available at: http://localhost:8090

How can we reproduce it (as minimally and precisely as possible)?

see above

Anything else we need to know?

No response

Host cluster Kubernetes version

```console ❯ kubectl version Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.3", GitCommit:"aef86a93758dc3cb2c658dd9657ab4ad4afc21cb", GitTreeState:"clean", BuildDate:"2022-07-14T02:31:37Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"} Kustomize Version: v4.5.4 Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.3", GitCommit:"816c97ab8cff8a1c72eccca1026f7820e93e0d25", GitTreeState:"clean", BuildDate:"2022-01-25T21:19:12Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"linux/amd64"} ```

Host cluster Kubernetes distribution

``` minikube -p vhost ```

vlcuster version

current main branch

Vcluster Kubernetes distribution(k3s(default)), k8s, k0s)

default

OS and Arch

``` ❯ cat /etc/os-release PRETTY_NAME="Ubuntu 21.10" NAME="Ubuntu" VERSION_ID="21.10" VERSION="21.10 (Impish Indri)" VERSION_CODENAME=impish ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=impish ```
guettli commented 1 year ago

I tried it with a different linux-user on my laptop, and now it works. This time my minikube cluster did not use a profile.

Maybe it is related to the -p option to minikube?

guettli commented 1 year ago

I guess it is related to skip push for local clusters

guettli commented 1 year ago

Found it. The name of the kube-context is important:

preferMinikube

DevSpace preferably uses the Docker daemon running in the virtual machine that belongs to your local Kubernetes cluster instead of your regular Docker daemon. This has the advantage that images do not need to be pushed to a registry because Kubernetes can simply use the images available in the Docker daemon belonging to the kubelet of the local cluster. Using this method is only possible when your current kube-context points to a local Kubernetes cluster and is named minikube, docker-desktop or docker-for-desktop.

https://devspace.sh/docs/5.x/configuration/images/docker#preferminikube

matskiv commented 1 year ago

@guettli you are correct :+1: :) I only had this problem when using minikube with -p option.

Also, there is no push option for KinD. In vclusters devspace.yaml we have a profile called "kind-load", which loads the built image into your KinD cluster. To use it you just add -p kind-load flag to the devspace commands. Perhaps --skip-push is also required, but I don't remember for sure.