ubuntu-20.04oracle-cloud-infrastructuremicrok8s

Unable to connect to Microk8s cluster built on OCI VM with kubectl


As the title says, I am unable to connect to a Microk8s cluster built on an OCI VM with the kubectl command from local Mac laptop. Please let me know if you know more about this.

environmental information.

VM

shape:"VM.Standard.A1.Flex"
CPU:2CORE
memory:8GB

OS

NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
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"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

network

cidr = 0.0.0.0/0
ports    = [
        "22",
        "80",
        "443",
        "6443",
        "2379",
        "2380",
        "8080",
        "10248",
        "10250",
        "10251",
        "10252",
        "16443",
        "30000-32767"
]

connection setting

kubeconfig

Paste the following into $HOME/.kube/config in local Mac.

- cluster:
    certificate-authority-data: XXXXXXXX.........
    server: https://<VM public IP>:16443
  name: microk8s-cluster
contexts:
- context:
    cluster: microk8s-cluster
    user: admin
  name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
  user:
    token: XXXXXXXXXXXX.......

ports

root@masternode:~# ss -ant
State                Recv-Q            Send-Q                            Local Address:Port                               Peer Address:Port            Process            
LISTEN               0                 4096                                  127.0.0.1:10248                                   0.0.0.0:*                                  
LISTEN               0                 4096                                  127.0.0.1:10249                                   
~~
LISTEN               0                 128                                        [::]:22                                         [::]:*                                  
LISTEN               0                 4096                                          *:16443                                         *:*                                  
ESTAB                0                 0                                         [::1]:16443                                     [::1]:33314                              
ESTAB                0                 0                            [::ffff:10.0.0.57]:16443                       [::ffff:10.1.181.1]:50704                              
ESTAB                0                 0                            [::ffff:10.0.0.57]:16443                        [::ffff:10.0.0.57]:13131                              
ESTAB                0                 0                                         [::1]:33314                                     [::1]:16443                              
ESTAB                0                 0                            [::ffff:127.0.0.1]:16443                        [::ffff:127.0.0.1]:34826                              
ESTAB                0                 0                            [::ffff:10.0.0.57]:16443                        [::ffff:10.0.0.57]:62508                              
ESTAB                0                 0                            [::ffff:127.0.0.1]:16443                        [::ffff:127.0.0.1]:53818                              
ESTAB                0                 0                            [::ffff:10.0.0.57]:16443                        [::ffff:10.0.0.57]:62920                              

Microk8s status

Microk8s status

root@masternode:~# microk8s status
microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    ha-cluster           # (core) Configure high availability on the current node
~~
    registry             # (core) Private image registry exposed on localhost:32000
    storage              # (core) Alias to hostpath-storage add-on, deprecated

node status

root@masternode:~# microk8s kubectl get nodes
NAME         STATUS   ROLES    AGE   VERSION
masternode   Ready    <none>   40m   v1.26.4

error information

takeruyamamura@TakerunoMini .kube % kubectl get nodes
E0429 04:18:58.717595   31573 memcache.go:238] couldn't get current server API group list: Get "https://168.138.89.20:16443/api?timeout=32s": dial tcp <public IP>:16443: connect: connection refused
...

What did I try

What do I expect


Solution

  • I was able to connect to the Microk8s cluster remotely after adding the Global IP to the configuration file according to the following site. microk8s, DEVOPS : Unable to connect to the server: x509: certificate is valid for <internal IPs>, not <external IP>