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

config set-context is not working #304

Closed
reyou opened this issue Feb 4, 2019 · 9 comments
Closed

config set-context is not working #304

reyou opened this issue Feb 4, 2019 · 9 comments

Comments

@reyou
Copy link

reyou commented Feb 4, 2019

inspection-report-20190204_171917.tar.gz
Please run microk8s.inspect and attach the generated tarball to this issue.

When I run following command

$ microk8s.kubectl config set-context qqq-staging --kubeconfig="/home/www/admin.conf"

Context "qqq-staging" modified.

and running following does not list created context:

$ microk8s.kubectl config get-contexts
CURRENT   NAME       CLUSTER            AUTHINFO   NAMESPACE
*         microk8s   microk8s-cluster   admin

Am I missing something here, or is it a known issue?

@GregoireW
Copy link

You trying to add a context on a file (/home/www/admin.conf) then ask context on default location (well the microk8s default location which is a read only file /snap/microk8s/current/client.config )
So, no mystery here: it will never return your context.

If you want to manage multiple contexts, you should do the opposite: extract the context of microk8s, add it to your main context file (~/.kube/config ) and use a standard kubectl

@reyou
Copy link
Author

reyou commented Feb 6, 2019

@GregoireW thanks for the insights, let me try this one.

@reyou
Copy link
Author

reyou commented Feb 6, 2019

@GregoireW I tried steps you mentioned, and this is what I have;

I am thinking following kubectl installed by conjure-up/microk8s wizard:

$ which kubectl
/snap/bin/kubectl
$ cat ~/.kube/config 

{myAdminConfigContentHere}

Following does not pick up my ~/.kube/config . Am I missing something here?
Seems like it still goes into microk8s config file.

$ kubectl config view

apiVersion: v1
clusters:
- cluster:
    server: http://127.0.0.1:8080
  name: microk8s-cluster
contexts:
- context:
    cluster: microk8s-cluster
    user: admin
  name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
  user:
    username: admin

@GregoireW
Copy link

Do you have an alias on kubectl ? alias kubectl ?
Do you have a KUBECONFIG environment variable ? echo $KUBECONFIG

Else... hum... I've no clue.

@reyou
Copy link
Author

reyou commented Feb 7, 2019

@GregoireW let me try those as well, thanks for the walkthrough :)
If those not work as well, I will try to install minukube instead of microk8s, maybe it will help.

@ktsakalozos
Copy link
Member

Hi @reyou,

Here is what I tried. First I moved the kubeconfig file that you need to access MicroK8s in the default location that is also read/write:

microk8s.kubectl config view > ~/.kube/config

Then I made sure I have a kubectl (other than the kubectl you get with microk8s):

sudo snap install kubectl --classic

At this point you should be able to access the MicroK8s cluster with kubectl. For example:

> kubectl get no
NAME               STATUS   ROLES    AGE    VERSION
jackal-vgn-fz11m   Ready    <none>   8m2s   v1.13.2

Adding the context with kubectl now works:

> kubectl config set-context qqq-staging 
Context "qqq-staging" created.

> kubectl config get-contexts
CURRENT   NAME          CLUSTER            AUTHINFO   NAMESPACE
*         microk8s      microk8s-cluster   admin      
          qqq-staging                             

microk8s.kubectl uses always the kubeconfig of microk8s stored on a read only location this is why you need a non-microk8s kubectl.

@nicja
Copy link

nicja commented Feb 8, 2019

If you always specify --kubeconfig=${KUBECONFIG} you will get consistent results. If that var is set microk8s.kubectl should always use it, but as per #259 this is not happening.

You could try use an alias, shell script or shell function to replace microk8s.kubectl with microk8s.kubectl --kubeconfig=${KUBECONFIG} "$@" and it should circumvent the issue as long as $KUBECONFIG is set to a regular file in a writable location.

@reyou
Copy link
Author

reyou commented Feb 11, 2019

Hello @ktsakalozos,

Thanks for your help.
Once I try to run following command:

sudo snap install kubectl --classic

I am getting following error as mentioned here #20 (comment)

sudo snap install kubectl --classic
error: cannot install "kubectl": snap "kubectl" command namespace conflicts with alias "kubectl"

Is there any easy way to fix this?

@reyou
Copy link
Author

reyou commented Feb 11, 2019

OK, I had to follow below;

https://blog.ubuntu.com/2017/01/28/ubuntu-core-how-to-enable-aliases-for-your-snaps-commands

snap aliases

snap unalias kubectl

@reyou reyou closed this as completed Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants