2

I have installed Canonical Kubernetes from Snap using:

$ sudo snap install k8s --classic

And I can use it like:

$ sudo k8s kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-5869d7778c-r87sf   1/1     Running   0          14h

How can I use it without sudo and the k8s command, like:

$ kubectl get pods
Command 'kubectl' not found, did you mean:
  command 'kubectx' from deb kubectx (0.9.5-1ubuntu0.2)
Try: sudo apt install <deb name>

Also, I would like an approach that can support bash-completion.


I was thinking of using the KUBECONFIG env var, but It seems that the kubectl is unknown to my command line and I also don't know the correct path for KUBECONFIG.

In addition, I was thinking of adding my user to the group, like how it can be done with microk8s, but there was no k8s group.

Mohsenasm
  • 123

1 Answers1

1

It seems you could define an alias for the k8s kubectl command, like this:

alias kubectl='k8s kubectl'

I'm not sure how sudo plays into this, but if it needs sudo, this could be part of the alias as well:

alias kubectl='sudo k8s kubectl'

A good place to put alias definitions is in ~/.bash_aliases.

Aliases are generally good for non-complex and non-scripted commands that are just meant to be run from CLI to return a result.

Also see here.

To make aliases work with auto-completion, see here.

Artur Meinild
  • 31,035