-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Proposal: Support copying or aliasing contexts #102
Comments
As I said in #101 I don't think it's a common case to both rely on GKE context names on dev machines AND provide user-friendly names for them. For a GKE advocate, I would highly discourage anyone from relying on gke context name pattern (i.e. gke_PROJECT_ZONE_CLUSTERNAME as you said) in any programming environment or scripting. Please use multiple kubeconfig files like the following for scripting/tooling:
However, this issue may have some merit. So I'll keep it open for a while to see if there's enough demand for it and what are their use cases. We would probably support this with a syntax similar to current renaming syntax ( As you noted in your PR #101, this complicates the context deletion since they would be sharing user/cluster entries. |
I can confirm @joemiller's example, we are running into similar issues where people want to use peronalized aliases for clusters. People from different teams work with different sets of cluster, some just with "their" clusters ("prod", "dev"), SRE do support multiple teams so they need "team1.prod", "team1.dev", "team2.prod" ... etc. We have implemented some developer workstation configuration management that does rollout team specific sets of kubeconfigs and the script itself is idempotent. If developers are suppossed to edit kubeconfigs for having cluster nicknames it would break any kind of kubeconfig configuration management. |
@cruschke this is a great use case report, thank you. |
I also am in need of this feature. This was actually implemented in the past, judging from 9ed6690#diff-10bafbbcaaa2bf26d2f237f58c279417 What was the rationale behind the decision to replace aliasing with renaming, instead of keeping both functions? |
Every time you alias, you end up with more contexts. And context name is meant to be used for human friendlines. This is also the reason why kubectl has a rename-context method. Can you explain your use case? Why do you need to clone your contexts? |
I am aware of that :)
Yet prominent cloud providers generate kubeconfigs via their CLI sdk with names that are not exactly user friendly. GKE has been cited above; DOKS is another one, for example.
because original ones are generated programmatically by third party tools, and I want to keep those untouched because I may need to re-run these tools, e.g. for credentials rotation or other configuration updates. |
I think as you said, I'd recommend doing what was deleted in 9ed6690#diff-10bafbbcaaa2bf26d2f237f58c279417 as a workaround. I'm hesitant about increasing the interaction surface for a feature that only a few people would use. The algorithm was:
Please do this as a bash function in the meanwhile as a workaround. If more people report this I might be open to adding, so keeping the issue open. 👍 |
+1 for aliases. Oracle's OKE also programatically generates kubeconfigs with randomised contexts, and I'd rather not touch the default configuration for reasons similar to those mentioned by @stefanotorresi. Renaming and aliasing should co-exist, since they cater to different use cases. |
+1 for aliases and the use case @cruschke mentioned where different teams have different aliases for the same clusters, and may have helper scripts that depend on those aliases. Yes, they should use a config file to store the cluster names, but they don't and my group doesn't have the ability to force them to. |
+1 we ran into the same issue with internal tooling expecting real cluster names instead of aliases. I'll do the work around and share with others, but I can't imagine a downside for making this the default behavior for aliasing contexts.. |
strike that. I was able to get this working by recreating the original context. I now have the aliased context and the original context listed, so I can reference the original name or the alias. |
Came here to file a similar request and saw this so just adding my vote in here. Use case: we have standardized, long-form context names that our (internal) tooling generates and expects (e.g. I just want to be able to reference it when doing ad hoc CLI work by going: |
Usually, when I create a new k8s cluster, it provides a new k8s config for this cluster, I have to manually merge the new context to # Assume default k8s config contains 5 contexts
kubectx | wc -l
5
# There is a new k8s config file contains 1 context
grep "\- context" ./config | wc -l
1
# Merge the new context into default config file
kubectx -m ./config
# The default k8s config will contain 6 contexts
kubectx | wc -l
6 |
@zhangsean kubectl already lets you merge kubeconfigs. You could easily search and find it. https://ahmet.im/blog/mastering-kubeconfig/ Furthermore this issue is clearly about duplicating/aliasing contexts which is NOT related to what you want. Please do not conflate these two things. Your request is a separate issue, and won’t be implement since it’s more suitable for kubectl itself or kubectl plugins (which I believe already exist). |
@ahmetb Thanks! |
In case anyone is still interested in this functionality, the tool kubeswitch might solve the alias problem for you by transparently defining the alias without changing the underlying kubeconfig file. Full disclosure: I am the author of it. |
Come across here when looking for a similar feature to manage my contexts. Thanks @danielfoehrKn for your sharing and I like the idea of creating alias separately other than modifying OTOH, I'm still thinking to have this feature inside @ahmetb If that makes sense, I'd be glad to spend some time to dig into it and submit a PR. Or, if that's not appropriate to have such stuff in |
Somewhere in your $PATH #!/bin/bash
#
# my wrapper script for kubectl ctx
# No argument, just do the normal thing
case $1 in
'') kubectl ctx
exit $?;;
esac
CONTEXTS="$(kubectl ctx)"
SELECT="$(echo "$CONTEXTS" | grep -i "$1")"
COUNT=$(echo "$SELECT" | wc -l)
case $COUNT in
0) echo "No context found for '$1'"
exit 1;;
1) kubectl ctx "$SELECT"
exit 0;;
*) echo "Multiple contexts found for '$1':"
echo "$SELECT"
exit 1;;
esac |
Example:
An engineering team using multiple GKE clusters may reasonably have these desires:
gke_project_zone_cluster-01
cluster-01
,cluster-02
, and so on.Currently
kubectx
supports renaming clusters which would address #2. However, renaming clusters would break use case #1.Providing an easy mechanism for copying contexts would allow for a straightforward way for the team to address both desires. By not renaming and keeping the full GKE name the team can distribute common tooling that relies on the full context name. And copying to a friendlier name makes it easier for the team to operate against multiple clusters, eg:
kubectl get pods --context cluster-01
orkubectx cluster-01
Implementing "copy" functionality would satisfy both desires.
The text was updated successfully, but these errors were encountered: