Tooling to easily access and switch between different OpenShift and/or OSD clusters
go get github.com/NautiluX/ocenv
To enable tab completion, add the following line to your ~/.bashrc
or similar init files.
complete -C ocenv ocenv
ocenv
can be used to log in to several OpenShift clusters at the same time.
Each cluster is referred to by a user-defined alias.
ocenv
creates a directory in ~/ocenv/
for each cluster named by the alias.
It contains an .ocenv
that will set $KUBECONFIG
and $OCM_CONFIG
when the environment is started.
You can run ocenv my-cluster
to create a new environment or switch between environments.
Each environment will use a separate $KUBECONFIG
so you can easily switch between them.
my-cluster
in this case is an alias that you can use to identify you cluster later.
Optionally, you can run ocenv -c my-cluster-id my-cluster
to set the $CLUSTERID
variable in the environment.
This is useful to log in to OSD clusters.
When using ocm
you can use the shorthands ocl
to log in to the cluster, oct
to create a tunnel when inside the environment, and ocb
to log in with the backplane plugin.
You can leave an environment by pressing ctrl+D
.
You can let ocenv detect the OCM environment and select a login script based on the environment you're currently logged in.
This will spare you to pass a script with the -l
argument each time you log in.
To use this feature, provide your login scripts in the config file ~/.ocenv.yaml
like in the following example:
loginScripts:
https://api.stage.openshift.com: ocm-stage-login
https://api.openshift.com: ocm-prod-login
https://api.integration.openshift.com: ocm-int-login
$ ocenv -l prod-login.sh -c hf203489-23fsdf-23rsdf my-cluster
$ ocb # login to the cluster
$ exit # tunnel and login loop will be closed on exit
...
$ ocenv my-cluster # no need to setup and remember everything again
$ ocb # login to the cluster
$ exit
$ ocenv -l prod-login.sh -t -c hf203489-23fsdf-23rsdf
$ ocb # login to the cluster
$ oc get pods .... # investigate
$ exit # tunnel and login loop will be closed on exit, environment will be cleaned up.
$ ocenv -l prod-login.sh -t -c hf203489-23fsdf-23rsdf my-cluster
$ ocb # login to the cluster
... in some other shell ...
$ `ocenv -k my-cluster` # use KUBECONFIG from environment
$ oc get pods ...
ocenv
supports creating environments for non-ocm-managed clusters as well.
You can either provide an API URL or an existing KUBECONFIG.
Set username, API url, and (optionally) password
$ ocenv -u myuser -p topsecret -a https://api.mycluster.com:6443 mycluster
Careful: The password will be stored in clear text if you pass it. In most cases it will be better to read it from STDIN on login.
log in with ocl
$ ocl
Log in with a kubeconfig that exists in the filesystem:
$ ocenv --kubeconfig ~/kube/config mycluster
Log in with a kubeconfig from clipboard (linux with xclip):
$ ocenv --kubeconfig <(xclip -o) mycluster
Log in with a kubeconfig from clipboard (Mac):
$ ocenv --kubeconfig <(pbpaste) mycluster