kubectl bash completion for alias with options - alias

I have several kubectl aliases configured:
alias k='kubectl'
alias kn='kubectl -n'
alias ks='kubectl -n kube-system'
alias ka='kubectl get --all-namespaces'
Bash completion works fine for kubectl and I got it working for most of the aliases as well by calling
complete -o default -F __start_kubectl $alias
This does however not work for the ka alias - the completion ignores that the get is already part of the alias and completes the command as if it wasn't there.
Is it possible to configure the completion to also work for the ka alias?
OS is a docker container using Ubuntu 16:04 as base image.

When aliasing kubectl use = options
From https://github.com/kubernetes/website/issues/31824#issue-1146171318
Setting flags/options in your alias requires the = format
Hence aliases should be created as follows:
alias k='kubectl'
alias kn='kubectl --namespace='
alias ks='kubectl --namespace=kube-system'
alias ka='kubectl --all-namespaces get'
alias kp="kubectl --kubeconfig=~/.kube/production.kubeconfig --namespace=prod"
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23",
GitVersion:"v1.23.5",
GitCommit:"c285e781331a3785a7f436042c65c5641ce8a9e9",
GitTreeState:"clean", BuildDate:"2022-03-16T15:58:47Z",
GoVersion:"go1.17.8", Compiler:"gc", Platform:"linux/amd64"}

Related

How are the --network options available in podman?

I am running a virtual environment on CentOS with podman.
When I used the --net option of the podman run command, I get an error.
[user#server ~]$ podman run --net slirp4netns:port_handler=slirp4netns -p 1080:80 -d --name web nginx
Error: cannot join CNI networks if running rootless: invalid argument
Is this option unavailable?
Or is there a problem with the way the options are specified?
Please tell me solution.
I used this site as a reference for the command.
This is the configuration of the server.
[user#server ~]$ cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
[user#server ~]$ podman -v
podman version 2.0.6
The port_handler option requires Podman >= 2.1.0, which isn't released at this moment: https://github.com/containers/podman/commit/d86bae2a01cb855d5964a2a3fbdd41afe68d62c8
You can use that option if you compile Podman from its master branch.
I find this link quite helpful to see rootless communication :
https://www.redhat.com/sysadmin/container-networking-podman
https://podman.io/getting-started/network
I am not sure if you have seen this link before or even if it is helpful to you at this instance. But, in view of helping others out, I think the blog post quotes the following helpful statements:
Note: All podman network commands are for rootfull containers only.
Technically, the container itself does not have an IP address, because without root privileges, network device association cannot be achieved
When using Podman as a rootless user, the network is setup automatically. The container itself does not have an IP Address, because without root privileges, network association is not allowed. You will also see some other limitations.

zsh alias not recognizing : command not found

Hellor everybody, i wanted to add an alias in my .zshrc file but please have a look at this i really don't understand
[23:29:36] charvet:~ $ expressvpn
NAME:
expressvpn - ExpressVPN command line interface
USAGE:
expressvpn command [arguments...]
VERSION:
1.1.0 (e822d60)
COMMANDS:
activate Activate account
connect Connect to VPN
disconnect Disconnect from VPN
status Display service information
list, ls List VPN locations
autoconnect Enable / disable auto-connect
protocol Display / change preferred protocol
refresh Refresh VPN clusters
reset Reset VPN account
diagnostics Display connection diagnostics
preferences List user preferences
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
Then i wrote in my file .zshrc
alias expressvpn=vpn
Then in zsh :
[23:29:46] charvet:~ $ source .zshrc
ls='ls --color=tty'
[23:29:52] charvet:~ $ vpn
zsh: command not found: vpn
[23:29:55] charvet:~ $
I am completely lost, i don't understand. People talk about the white space around the "=" but i haven't any.
Try alias vpn=expressvpn?
Try help alias for help with alias syntax.
You have to say in your profile
alias expressvpn= 'vpn'
that's how it works

Change directory on remote server with zsh

I usually ssh into my aws account then immediately change directory to my working directory.
I am now using an alias in my .zshrc file for the ssh command. However , ideally, I'd like to ssh in then change directories automatically with my alias command. Cant figure out the cd part on the remote server. My alias looks something like this now:
alias aws="ssh -i ~/.ssh/mykeypair.pem ubuntu#11.11.111.11"
I think the preferred way would be creating ~/.zshrc or ~/.bashrc file on your remote host or appending to the end just:
cd your/working/directory/
Just tested and works fine for me
Other way would be changing your alias to something like:
alias aws="ssh -tt -i ~/.ssh/mykeypair.pem ubuntu#11.11.111.11 'cd your/working/directory/; bash'"
Additionally you can change bash for zsh if you want to use zsh as your shell on remote host.

docker run cannot find name flag argument

I have recently setup a Rstudio application on Google compute container engine using Docker and the Rocker/rstudio package. Now I want to start my saved container with a name using the following ssh command line:
sudo docker -d -p 8787:8787 --name samplename user/laatste
which returns the following error
flag provided but not defined: --name
I have tried with and without quotes, equal signs, double and single hyphens, before, between and after the other flags and arguments, but the same error keeps returning.
version information:
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef
The reason I want to name the container is that I want to run standard (static) startup and shutdown scripts with the Google compute instance to automatically save and load changes made in R. The container name is used for identifying the container to be saved. Any other solution for this is also very welcome.
I guess you wanted to do:
sudo docker run -d -p 8787:8787 --name samplename user/laatste
You forgot to specify command (run) here.

how to use ionice with alias

ionice does not seem to work with aliases. I am using zsh, I did not test bash. e.g.
$ alias foo='ls -l'
$ ionice -c2 -n2 foo
ionice: executing foo failed: No such file or directory
Why does ionice not recognice the alias and how can I get it to recognize the alias?
You need to use a global alias:
alias -g foo='ls -l'