minikube 不适用于生产环境,只适合玩玩,研究太多没有多大意义,建议转向 MicroK8s
set kubectl connect to remote minikube from local
1. before install minikube, you need install docker first.
Install Docker Engine on Ubuntu
2. create a new user, because minikube can not start from root user.
# create a user called docker, add to group docker
useradd docker docker
modify docker as sudo user
usermod -aG sudo docker
3. now you can start your minikube
minikube start
check your cluster info
docker@minikube:~/.kube$ kubectl cluster-info
Kubernetes control plane is running at https://192.168.49.2:8443
4. now let generate SSH key for user docker
ssh-keygen
now, you have your key-pairs in you home dir
docker@minikube:~$ ls -lah .ssh/
-rw------- 1 docker docker 2.6K Jun 19 15:18 id_rsa
-rw-r--r-- 1 docker docker 569 Jun 19 15:18 id_rsa.pub
very inportant: chmod 0700 ~ && chmod 600 ~/.ssh & chmod 600 *
, otherwise, you will get surprise.
cat ./.ssh/id_rsa
to get your private key.
5. ssh-keygen in local to generate .ssh folder
get in to the folder,
- create a pem file
minikube_docker.pem
, peste the content of.ssh/id_rsa
from remote server. - give 600 permission to this file:
chmod 600 minikube_docker.pem
- you can create
config
file if you do not have it, and append the content below:Host aliyun_minikube HostName YOUR_REMOTE_HOSTING_IP User docker IdentityFile ~/.ssh/minikube_docker.pem
now, try connect to your remote server:
~/.ssh$ ssh aliyun_minikube Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-74-generic x86_64)
and actually, you can manage your minikube cluster now.
docker@minikube:~$ kubectl cluster-info Kubernetes control plane is running at https://192.168.49.2:8443docker@minikube:~$ kubectl cluster-info
6. but we can do something more, instead login to remote server, we can manage minikube from local direclty.
now we known minikube running on ip:192.168.49.2 port: 8443
本地minikube命令访问远程minikube集群
ssh -L 18443:192.168.49.2:8443 -N -f aliyun_minikube
install kubectl to your local.
go to remote server, get kubectl config, save it to local in the same palce, ~/.kube/config
docker@minikube:~$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority: /home/docker/.minikube/ca.crt
extensions:
- extension:
last-update: Sat, 19 Jun 2021 14:45:54 CST
provider: minikube.sigs.k8s.io
version: v1.21.0
name: cluster_info
server: https://192.168.49.2:8443
name: minikube
contexts:
- context:
cluster: minikube
extensions:
- extension:
last-update: Sat, 19 Jun 2021 14:45:54 CST
provider: minikube.sigs.k8s.io
version: v1.21.0
name: context_info
namespace: default
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate: /home/docker/.minikube/profiles/minikube/client.crt
client-key: /home/docker/.minikube/profiles/minikube/client.key
notice: certificate-authority
, certificate-authority
, certificate-authority
get the content, save to local.
now, you can connect to you minikube in remote server from local.
~$ kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 5h22m v1.20.7