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

一、先决条件

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

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

二、安装 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

  1. minikube node list
  2. 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

  1. # 新开窗口运行
  2. minikube tunnel --cleanup=true
  3. # 重新部署
  4. kubectl delete deployment nginx
  5. kubectl delete service nginx
  6. kubectl create deployment nginx --image=nginx
  7. kubectl expose deployment nginx --port=80 --type=LoadBalancer
  8. # 查看外部地址
  9. 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