crc-org / crc

CRC is a tool to help you run containers. It manages a local OpenShift 4.x cluster, Microshift or a Podman VM optimized for testing and development purposes
https://crc.dev
Apache License 2.0
1.25k stars 240 forks source link

[BUG] kubeconfig context is not detected properly #3725

Closed datho7561 closed 1 year ago

datho7561 commented 1 year ago

General information

CRC version

CRC version: 2.20.0+f3a947
OpenShift version: 4.13.0
Podman version: 4.4.4

CRC status

DEBU CRC version: 2.20.0+f3a947
DEBU OpenShift version: 4.13.0
DEBU Podman version: 4.4.4
DEBU Running 'crc status'
CRC VM:          Running
MicroShift:      Running (v4.13.0)
RAM Usage:       1.317GB of 3.902GB
Disk Usage:      4.814GB of 16.1GB (Inside the CRC VM)
Cache Usage:     54.43GB
Cache Directory: /home/davthomp/.crc/cache

CRC config

- consent-telemetry                     : yes
- preset                                : microshift

Host Operating System

NAME="Fedora Linux"
VERSION="38 (Workstation Edition)"
ID=fedora
VERSION_ID=38
VERSION_CODENAME=""
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Linux 38 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f38/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=38
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=38
SUPPORT_END=2024-05-14
VARIANT="Workstation Edition"
VARIANT_ID=workstation

Steps to reproduce

  1. Set the preset to MicroShift
  2. Make sure libvirtd is enabled and started
  3. crc setup
  4. crc start
  5. oc get deployment

Expected

A list of the deployments on the current namespace in the cluster (or a "permission denied" error).

Actual

E0619 16:06:53.277096  110818 memcache.go:238] couldn't get current server API group list: Get "https://localhost:6443/api?timeout=32s": dial tcp [::1]:6443: connect: connection refused
E0619 16:06:53.277377  110818 memcache.go:238] couldn't get current server API group list: Get "https://localhost:6443/api?timeout=32s": dial tcp [::1]:6443: connect: connection refused
E0619 16:06:53.278700  110818 memcache.go:238] couldn't get current server API group list: Get "https://localhost:6443/api?timeout=32s": dial tcp [::1]:6443: connect: connection refused
E0619 16:06:53.280027  110818 memcache.go:238] couldn't get current server API group list: Get "https://localhost:6443/api?timeout=32s": dial tcp [::1]:6443: connect: connection refused
E0619 16:06:53.281328  110818 memcache.go:238] couldn't get current server API group list: Get "https://localhost:6443/api?timeout=32s": dial tcp [::1]:6443: connect: connection refused
The connection to the server localhost:6443 was refused - did you specify the right host or port?

If I switch the cluster server address to the IP that's output as a part of crc start, then try running, oc get deployment, I get this instead:

E0619 16:10:30.185774  111325 memcache.go:238] couldn't get current server API group list: Get "https://192.168.130.11:6443/api?timeout=32s": x509: certificate signed by unknown authority
E0619 16:10:30.187393  111325 memcache.go:238] couldn't get current server API group list: Get "https://192.168.130.11:6443/api?timeout=32s": x509: certificate signed by unknown authority
E0619 16:10:30.188963  111325 memcache.go:238] couldn't get current server API group list: Get "https://192.168.130.11:6443/api?timeout=32s": x509: certificate signed by unknown authority
E0619 16:10:30.190742  111325 memcache.go:238] couldn't get current server API group list: Get "https://192.168.130.11:6443/api?timeout=32s": x509: certificate signed by unknown authority
E0619 16:10:30.192345  111325 memcache.go:238] couldn't get current server API group list: Get "https://192.168.130.11:6443/api?timeout=32s": x509: certificate signed by unknown authority
Unable to connect to the server: x509: certificate signed by unknown authority

Logs

https://gist.github.com/datho7561/62661d08feb48a5431346308752a743c

praveenkumar commented 1 year ago

@datho7561 This looks like your kubeconfig doesn't updated correctly or you are using a different context from the kubeconfig. Can you check oc config get-contexts and make sure microshift is selected?

datho7561 commented 1 year ago

The current context is microshift in the .kube/config, and this is also reported when running oc config get-contexts. The cluster entry for microshift has the server set to https://localhost:6443. I'm pretty sure that this entry was created by crc, but I want to double check. What is the best way to regenerate the .kube/config? I'll try deleting the cluster (crc delete) and kubeconfig file, then recreate the cluster.

datho7561 commented 1 year ago

I tried deleting the microshift cluster and my .kube/config, then regenerating the cluster, and I got the same cluster entry, where the cluster URL is set to https://localhost:6443

praveenkumar commented 1 year ago

@datho7561 can you try following and let me know if that works?

$ crc delete
$ crc cleanup
$ crc config set network-mode user
$ crc setup
$ crc start
$ oc get pods -A
datho7561 commented 1 year ago

That worked. Thanks! I'm able to access pods and deployments now.

praveenkumar commented 1 year ago

@datho7561 Great, looks like there is some change around how kubeconfig file is generated for alternative domain and we need to use the api.crc.testing one https://github.com/openshift/microshift/blob/main/docs/howto_kubeconfig.md