This page looks best with JavaScript enabled

Building a Remote Kubernetes Development Environment

Minikube is a single-node distribution of Kubernetes, suited to product evaluation and day-to-day development. Here we use Minikube to build a development environment: Kubernetes runs on a CentOS cloud server, and development happens remotely from a local OS X machine.

1. Install Minikube on the Cloud Server

On the Minikube GitHub releases page, find a suitable version and install it.

Taking CentOS as an example, run:

1
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.2.0/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube

minikube is an executable binary; after downloading it, just add the executable permission. For installing Docker, please refer to here.

2. Run Minikube on the Cloud Server

Use the --vm-driver parameter to tell minikube to use the Docker environment already installed on CentOS. Run the command to start Minikube:

1
minikube start --vm-driver=none

Start the Dashboard:

1
minikube dashboard

If it fails to start, you can try running kubectl proxy --address='0.0.0.0' --disable-filter=true and visiting http://127.0.0.1:8001/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your browser.

Try deploying an application:

1
kubectl run kube-nginx --image=nginx:latest --port=80

Check the POD information:

1
2
3
kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
kube-nginx-7c765ffd95-v6gc9   1/1     Running   1          2m

3. Install kubectl Locally

kubectl is the client management tool for a Kubernetes cluster. Together kubectl and Kubernetes form a CS architecture model, and they can run on different machines.

Taking OS X as an example, install kubectl with:

1
brew install kubernetes-cli

4. Configure kubectl Locally

Copy the minikube authentication information from the server by running locally:

mkdir ~/.kube
scp -r root@your_host_ip:/root/.kube/config ~/.kube/config
mkdir ~/.minikube
scp -r root@your_host_ip:/root/.minikube/\{ca.crt,client.crt,client.key\} ~/.minikube/

Modify the kubectl configuration file

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
    # 修改为 ca.crt 的正确路径
    # certificate-authority: ../.minikube/ca.crt
    # 修改为服务器的 IP 地址
    server: https://your_host_ip:8443
    # 不校验证书,否则会提示 x509 校验失败
    insecure-skip-tls-verify: true
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    # 修改为 client.crt 的正确路径
    client-certificate: ../.minikube/client.crt
    # 修改为 client.key 的正确路径
    client-key: ../.minikube/client.key

View the Pod information in the remote Kubernetes cluster:

1
2
3
kubectl get pods
NAME                          READY     STATUS    RESTARTS   AGE
kube-nginx-7c765ffd95-2pxfk   1/1       Running   0          11m

5. References


WeChat Official Account
WRITTEN BY
WeChat Official Account