[Kubernetes] Adding On-Premise Kubernetes Context in Local PC
Adding On-Premise Kubernetes Context in Local PC
- In the On-Premise K8s Cluster
kubectl create serviceaccount {USER_NAME}
# serviceaccount/ed created
kubectl create clusterrolebinding {USER_NAME}-binding \
--clusterrole=cluster-admin \
--serviceaccount=default:{USER_NAME}
# clusterrolebinding.rbac.authorization.k8s.io/ed-binding created
kubectl create token {USER_NAME}
eyJhbGciOiJSUzI1NiIsImtpZCI6Il91OW... (some long token)
cat /etc/kubernetes/pki/ca.crt
-----BEGIN CERTIFICATE-----
MIIDBTCCAe2gAwIBAgIIOehvyXNS9WkwDQYJKoZIhvcNAQELBQAwFTETMBEGA1UE
... some kind of token
-----END CERTIFICATE-----
- In the Local PC
- Save the result of
ca.crtascompany-ca.crt
# 1. Add the internal cluster
kubectl config set-cluster {CLUSTER_NAME} \
--server=https://{CLUSTER_MASTER_IP}:6443 \
--certificate-authority=/path/to/company-ca.crt \
--embed-certs=true
# 2. Add your user credentials
kubectl config set-credentials your-user-name --token={TOKEN}
# 3. Create the context link
kubectl config set-context {CLUSTER_NAME} \
--cluster={CLUSTER_NAME} \
--user={USER_NAME}