Minikube 安装和简单使用

CentOS7 安装 Minikube,用于学习使用,可以在一台节点上很方便的部署 K8S 集群环境

 

一、先决条件

安装 Docker:https://www.cnblogs.com/jhxxb/p/11410816.html

安装 kubectl:https://kubernetes.io/docs/tasks/tools/

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client

 

二、安装 Minikube

https://minikube.sigs.k8s.io/docs/start/

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

 

三、启动

minikube start

默认为单节点,可添加节点,https://minikube.sigs.k8s.io/docs/commands/node

minikube node list
minikube node add

可视化

minikube dashboard --url
# 让其它 IP 可以访问
kubectl proxy --port=8888 --address='0.0.0.0' --accept-hosts='^.*'

访问:http://10.74.2.71:8888/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview?namespace=_all

 

四、部署应用与访问应用

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
# 获取访问地址
minikube service --url nginx

# 也可以通过 kubectl proxy 拼接 url 访问,https://kubernetes.io/zh/docs/tasks/access-application-cluster/access-cluster/#manually-constructing-apiserver-proxy-urls
# http://10.74.2.71:8888/api/v1/namespaces/default/services/nginx:80/proxy/

使用负载均衡访问,Minikube 网络:https://minikube.sigs.k8s.io/docs/handbook/accessing

# 新开窗口运行
minikube tunnel --cleanup=true

# 重新部署
kubectl delete deployment nginx
kubectl delete service nginx
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=LoadBalancer
# 查看外部地址
kubectl get svc

通过转发访问,https://kubernetes.io/zh/docs/tasks/access-application-cluster/port-forward-access-application-cluster

kubectl port-forward pods/nginx-6799fc88d8-p8llb 8080:80 --address='0.0.0.0'

 

五、卸载

https://minikube.sigs.k8s.io/docs/commands/delete

minikube stop
minikube delete --all
docker rmi kicbase/stable:v0.0.25
rm -rf ~/.kube ~/.minikube
sudo rm -rf /usr/local/bin/kubectl /usr/local/bin/minikube
docker system prune -a

 


https://github.com/AliyunContainerService/minikube/wiki

https://kubernetes.io/zh/docs/tutorials/hello-minikube

https://www.cnblogs.com/k4nz/p/14543016.html

posted @ 2021-11-03 23:11  江湖小小白  阅读(13280)  评论(0编辑  收藏  举报