---
# System prepended metadata

title: Remotely Access to Cluster
tags: [DevOps, CI/CD, Infra, III]

---

Remotely Access to Cluster
===

###### tags: `III` `DevOps` `Infra` `CI/CD`

## kubectl
裝 [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) 之後
* Add cluster
:::info
CERTIFICATE_AUTHORITY_DATA 是 /etc/kubernetes/pki/ca.crt 的內容
:::
```
kubectl config set-cluster abby-cluster --server=https://10.22.100.233:6443
kubectl config set clusters.abby-cluster.certificate-authority-data $CERTIFICATE_AUTHORITY_DATA
```
或
```
kubectl config set-cluster abby-cluster --server=https://10.22.100.233:6443 --certificate-authority=<CERTIFICATE_AUTHORITY_DATA_FILE>
```
* Add user
:::info
CLIENT_KEY 是 /etc/kubernetes/pki/apiserver-kubelet-client.key 的內容
CLIENT_CERTIFICATE 是 /etc/kubernetes/pki/apiserver-kubelet-client.crt 的內容
:::
```
kubectl config set-credentials abby 
kubectl config set users.abby.client-certificate $CLIENT_CERTIFICATE
kubectl config set users.abby.client-key $CLIENT_KEY
```
或
```
kubectl config set-credentials abby --client-certificate=<CLIENT_CERTIFICATE_FILE> --client-key=<CLIENT_KEY_FILE>
```
* Add context
```
kubectl config set-context abby-context --cluster=abby-cluster --namespace=abby-ns --user=abby
```
* Set current context
```
kubectl config use-context abby-context
```
* Check config
```
kubectl config view
```