-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Summary
When running kops create cluster while an existing ~/.kube/config file is present, kOps does not correctly merge the kubeconfig entries for the newly created cluster.
The cluster entry is added, but the generated context references an empty user, and no corresponding user entry is added under users:. This results in an unusable kubeconfig unless it is manually fixed or regenerated.
If ~/.kube/config does not exist before running kops create, the kubeconfig is generated correctly.
kOps Version
Client Version:1.34.1 (git-v1.34.1)
Kubernetes Version
Client Version: v1.35.0
Kustomize Version: v5.7.1
Server Version: v1.34.3
Operating System
Ubuntu
Cloud provider
AWS
Steps to Reproduce
Ensure an existing kubeconfig is present (for example from Minikube):
ls ~/.kube/config
Create a cluster using kOps:
kops create cluster --name=kops.example.com ...
kops update cluster --yes
Inspect the kubeconfig:
cat ~/.kube/config
Actual Behavior
- The new cluster entry is added.
- A context is created, but the user field is empty.
- No corresponding user entry is added under users:.
Example (redacted):
contexts:
- context:
cluster: kops.example.com
user: ""
name: kops.example.com
The users: section does not contain a matching user for the kOps cluster.
This results in kubectl authentication failures unless the user entry is manually added or kubeconfig is regenerated.
Expected Behavior
When ~/.kube/config already exists, kops create should:
- Add the cluster entry
- Add a corresponding user entry
- Create a context that correctly references that user
Same behavior as when no kubeconfig exists.
Working Scenario
If ~/.kube/config is removed before running kops create:
rm ~/.kube/config
kops create cluster ...
kops update cluster --yes
Then the generated kubeconfig is correct and includes:
- Cluster
- User
- Context referencing that user
contexts:
- context:
cluster: kops.example.com
user: kops.example.com
name: kops.example.com
users:
- name: kops.example.com
user:
client-certificate-data: <redacted>
client-key-data: <redacted>
Impact
This behavior breaks multi-cluster kubeconfig setups and requires manual intervention or deletion of the existing kubeconfig, which is not ideal.