介绍
minikube 是适合开发人员的迷你版 k8s,本文在 ubuntu 18.04 上安装 minikube。
安装minikube
To install the latest minikube stable release on x86-64 Linux using binary download:
|
|
启动minikube
From a terminal with administrator access (but not logged in as root), run:
|
|
If minikube fails to start, see the drivers page for help setting up a compatible container or virtual-machine manager.
安装kubectl
用以下命令下载最新 kubectl 发行版
|
|
安装 kubectl
|
|
测试
|
|
操作
使用 kubectl 查看所有命名空间的 pod
|
|
minikube 集成了 kubernetes dashboard,使用如下命令开启访问 dashboard
|
|
查看 minikube 版本
|
|
部署服务
k8s 有三种暴露服务的方式:NodePort, LoadBalancer, Ingress,分别介绍使用minikube 安装暴露服务
Service
Create a sample deployment and expose it on port 8080:
|
|
It may take a moment, but your deployment will soon show up when you run:
|
|
The easiest way to access this service is to let minikube launch a web browser for you:
|
|
Alternatively, use kubectl to forward the port:
|
|
Tada! Your application is now available at http://localhost:7080/.
You should be able to see the request metadata in the application output. Try changing the path of the request and observe the changes. Similarly, you can do a POST request and observe the body show up in the output.
LoadBalancer
To access a LoadBalancer deployment, use the “minikube tunnel” command. Here is an example deployment:
|
|
In another window, start the tunnel to create a routable IP for the ‘balanced’ deployment:
|
|
To find the routable IP, run this command and examine the EXTERNAL-IP column:
|
|
Your deployment is now available at <EXTERNAL-IP>:8080
Ingress
Enable ingress addon:
|
|
The following example creates simple echo-server services and an Ingress object to route to these services.
|
|
Apply the contents
|
|
Wait for ingress address
|
|
Note for Docker Desktop Users:
To get ingress to work you’ll need to open a new terminal window and run minikube tunnel and in the following step use 127.0.0.1 in place of <ip_from_above>
.
Now verify that the ingress works
|
|
管理minikube
Pause Kubernetes without impacting deployed applications:
|
|
Unpause a paused instance:
|
|
Halt the cluster:
|
|
Change the default memory limit (requires a restart):
|
|
Browse the catalog of easily installed Kubernetes services:
|
|
Create a second cluster running an older Kubernetes release:
|
|
Delete all of the minikube clusters:
|
|
参考:
https://kubernetes.io/zh-cn/docs/tutorials/hello-minikube/
https://minikube.sigs.k8s.io/docs/start/
https://kubernetes.io/zh-cn/docs/tasks/tools/#kubectl
https://kubernetes.io/zh-cn/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux