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

一、先决条件

安装Docker

Docker安装和启动

安装kubelet kubeadm kubectl

安装升级Kubernetes基础组件kubelet kubeadm kubectl

二、安装 Minikube

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

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

三、启动

  1. minikube start
默认为单节点,可添加节点,https://minikube.sigs.k8s.io/docs/commands/node bash minikube node list minikube node add Minikube 安装和简单使用 - 图1 可视化
  1. minikube dashboard --url # 让其它 IP 可以访问
  2. 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

Minikube 安装和简单使用 - 图2

四、部署应用与访问应用

  1. kubectl create deployment nginx --image=nginx
  2. kubectl expose deployment nginx --port=80 --type=NodePort
  3. # 获取访问地址
  4. minikube service --url nginx
  5. # 也可以通过 kubectl proxy 拼接 url 访问,https://kubernetes.io/zh/docs/tasks/access-application-cluster/access-cluster/#manually-constructing-apiserver-proxy-urls
  6. # http://10.74.2.71:8888/api/v1/namespaces/default/services/nginx:80/proxy/

Minikube 安装和简单使用 - 图3

使用负载均衡访问,Minikube 网络:https://minikube.sigs.k8s.io/docs/handbook/accessing bash # 新开窗口运行 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 Minikube 安装和简单使用 - 图4 通过转发访问,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

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