1

Is there any shorter alias on the kubectl/oc for deployments? In OpenShift you have deployment configurations and you can access them using their alias dc.

Writing deployment all the time takes too much time. Any idea how to shorten that without setting a local alias on each machine?

Reality:

kubectl get deployment/xyz

Dream:

kubectl get d/xyz
Rtholl
  • 75
  • 4

3 Answers3

5

All of the above answers are correct and I endorse the idea of using aliases: I have several myself. But the question was fundamentally about shortnames of API Resources, like dc for deploymentcontroller.

And the answer to that question is to use oc api-resources (or kubectl api-resources). Each API Resource also includes any SHORTNAMES that are available. For example, the results for me of oc api-resources |grep deploy on OpenShift 4.10 is:

âžœoc api-resources |grep deploy
deployments                           deploy              apps/v1                                         true         Deployment
deploymentconfigs                     dc                  apps.openshift.io/v1                            true         DeploymentConfig

Thus we can see that the previously given answer of "deploy" is a valid SHORTNAME of deployments. But it's also useful for just browsing the list of other available abbreviations.

I'll also make sure that you are aware of oc completion. For example source <(oc completion zsh) for zsh. You say you have multiple devices, so you may not set up aliases, but completions are always easy to add. That way you should never have to type more than a few characters and then autocomplete yourself the rest of the way.

David Ogren
  • 4,396
  • 1
  • 19
  • 29
1

Add bash aliases to different K8s commands in your .bashrc or .zshrc file:

export alias k=kubectl
export alias kgd="k get deploy" # deploy is the short name of deployment 

Some other helpful aliases:

alias k="kubectl"
alias kgp="k get po"
alias kgs="k get svc"
alias kg="k get"
alias kc="k create"
alias kr="k run"
alias ka="k apply -f "
alias kpf="k port-forward"
alias kds="k describe"
alias kd="k delete"
Taimoor Mirza
  • 1,093
  • 7
  • 19
  • 1
    thanks for the "deploy" hint. This is already a bit shorter than deployment :) I often work on different devices, so maintaining a set of aliases across them is a pain... – Rtholl Aug 15 '22 at 08:34
0

you can create an alias or you can can add plugin in the ~/.zshrc

vi ~/.zshrc

and add

plugins=(
  kubectl
)

then you can use the common alias given below or kgd

or you can try

# Deployment management.
alias kgd='kubectl get deployment'

and then

kgd

There are a couple of aliases that you can use regarding deployment.

|         |                                     | **Deployment management**                                                                        |
| kgd     | `kubectl get deployment`            | Get the deployment                                                                               |
| kgdw    | `kgd --watch`                       | After getting the deployment, watch for changes                                                  |
| kgdwide | `kgd -o wide`                       | After getting the deployment, output in plain-text format with any additional information        |
| ked     | `kubectl edit deployment`           | Edit deployment resource from the default editor                                                 |
| kdd     | `kubectl describe deployment`       | Describe deployment resource in detail                                                           |
| kdeld   | `kubectl delete deployment`         | Delete the deployment                                                                            |
| ksd     | `kubectl scale deployment`          | Scale a deployment                                                                               |
| krsd    | `kubectl rollout status deployment` | Check the rollout status of a deployment                                                         |
| kres    | `kubectl set env $@ REFRESHED_AT=...` | Recreate all pods in deployment with zero-downtime 

you can find more common list here

Adiii
  • 54,482
  • 7
  • 145
  • 148