Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using kubeconfig from Rancher does not work #32

Closed
matt-canty-dragon opened this issue Feb 25, 2020 · 7 comments
Closed

Using kubeconfig from Rancher does not work #32

matt-canty-dragon opened this issue Feb 25, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@matt-canty-dragon
Copy link

matt-canty-dragon commented Feb 25, 2020

I tried using the kubeconfig approach to using kubenav. The Add Clusters popup includes a note to say:

this only works if your Kubeconfig file contains the certificate in the certificate-authority-data field.

image

My kubeconfig contains `certificate-authority-data` however it is on a fqdn cluster...:

image

alas...

image

Appreciate what you have done, it looks great. I look forward to checking back another time!

@ricoberger
Copy link
Member

Hi, what I can see from your provided Kubeconfig, the problem is within the first cluster (***-apps), where the certificate-authority-data key is missing. You can try to add the ***-apps-fqdn cluster via the manual option, since the certificate-authority-data key is required at the moment.

For desktop this should be fixed in #25. For the mobile version of kubenav, I will come up with a PR for the next version where the certificate-authority-data key becomes optional.

@ricoberger
Copy link
Member

Hi @matt-canty-dragon, on desktop you can try out the nightly builds where the fix for your issue is included.

@ricoberger ricoberger added the bug Something isn't working label Feb 25, 2020
@matt-canty-dragon
Copy link
Author

I downloaded https://storage.googleapis.com/kubenav/2020-03-01/kubenav-1.2.0-darwin-amd64.dmg

I get this in the clusters page

image

@ricoberger
Copy link
Member

Mh currently I have no idea, whats going wrong there. There are some open issues regarding certificates in the http://github.com/kubernetes-client/javascript repo, but I do not know if they are related.

Do you have node installed and can run the following, this would be super helpful to see if the error is within kubenav or the used client library:

mkdir test
cd test

cat <<EOF >> package.json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@kubernetes/client-node": "^0.11.1",
    "request": "^2.88.2"
  }
}
EOF

cat <<EOF >> index.js
const request = require('request');
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const opts = {
    url: kc.getCluster(kc.getContextObject(kc.getCurrentContext()).cluster).server + '/api/v1/namespaces',
    method: 'GET',
};

kc.applyToRequest(opts);

request(opts, (error, response, body) => {
    if (error) {
        console.log('ERROR');
        console.log(error);
    } else {
        if (!(response.statusCode >= 200 && response.statusCode < 300)) {
            console.log('ERROR');
            console.log(body);
        } else {
            console.log('SUCCESS');
            console.log(body)
        }
    }
});
EOF

npm install

node index.js

The script uses the current context from your Kubeconfig file and returns all Namespaces. If there is an error the error will be printed.

@matt-canty-dragon
Copy link
Author

Hey so it's working now. I did the following: given some KUBECONFIGs

apiVersion: v1
kind: Config
clusters:
- name: "cluster-1"
  cluster:
    server: "https://rancher.REDACTED"
- name: "cluster-1-fqdn"
  cluster:
    server: "https://internal-REDACTED"
    certificate-authority-data: "REDACTED"

users:
- name: "u-abcd123-cluster-1"
  user:
    token: "kubeconfig-REDACTED"

contexts:
- name: "cluster-1"
  context:
    user: "u-abcd123-cluster-1"
    cluster: "cluster-1"
- name: "cluster-1-fqdn"
  context:
    user: "u-abcd123-cluster-1"
    cluster: "cluster-1-fqdn"

current-context: "cluster-1"
apiVersion: v1
kind: Config
clusters:
- name: "cluster-2"
  cluster:
    server: "https://rancher.REDACTED"
- name: "cluster-2-fqdn"
  cluster:
    server: "https://internal-REDACTED"
    certificate-authority-data: "REDACTED"

users:
- name: "u-abcd123-cluster-2"
  user:
    token: "kubeconfig-REDACTED"

contexts:
- name: "cluster-2"
  context:
    user: "u-abcd123-cluster-2"
    cluster: "cluster-2"
- name: "cluster-2-fqdn"
  context:
    user: "u-abcd123-cluster-2"
    cluster: "cluster-2-fqdn"

current-context: "cluster-2"

I merged them and removed the fqdn cluster definitions

apiVersion: v1
clusters:
- cluster:
    server: https://rancher.REDACTED
  name: cluster-1
- cluster:
    server: https://rancher.REDACTED
  name: cluster-2
contexts:
- context:
    cluster: cluster-1
    namespace: card-service
    user: u-abcd123-cluster-1
  name: cluster-1
- context:
    cluster: cluster-2
    namespace: monitoring
    user: u-abcd123-cluster-2
  name: cluster-2
current-context: cluster-1
kind: Config
preferences: {}
users:
- name: u-abcd123-cluster-1
  user:
    token: kubeconfig-REDACTED
- name: u-abcd123-cluster-2
  user:
    token: kubeconfig-REDACTED

This works for cluster selection, however now I have another issue:

How do I switch namespaces?
I have to do this a lot. I can see how I view namespace

@ricoberger
Copy link
Member

Hi, good to hear. There is a filter icon in the top right corner in the list view for a resource. When you click on the icon a list with all your namespaces becomes visible and you can select one.

Bildschirmfoto 2020-03-03 um 18 49 55

@matt-canty-dragon
Copy link
Author

Nice. I really like it. So lean.

Bravo 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants