知乎专栏 |
[root@localhost ~]# minikube Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows. Usage: minikube [command] Available Commands: addons Modify minikube's kubernetes addons cache Add or delete an image from the local cache. completion Outputs minikube shell completion for the given shell (bash or zsh) config Modify minikube config dashboard Access the kubernetes dashboard running within the minikube cluster delete Deletes a local kubernetes cluster docker-env Sets up docker env variables; similar to '$(docker-machine env)' help Help about any command ip Retrieves the IP address of the running cluster logs Gets the logs of the running instance, used for debugging minikube, not user code mount Mounts the specified directory into minikube profile Profile sets the current minikube profile service Gets the kubernetes URL(s) for the specified service in your local cluster ssh Log into or run a command on a machine with SSH; similar to 'docker-machine ssh' ssh-key Retrieve the ssh identity key path of the specified cluster start Starts a local kubernetes cluster status Gets the status of a local kubernetes cluster stop Stops a running local kubernetes cluster tunnel tunnel makes services of type LoadBalancer accessible on localhost update-check Print current and latest version number update-context Verify the IP address of the running cluster in kubeconfig. version Print the version of minikube Flags: --alsologtostderr log to standard error as well as files -b, --bootstrapper string The name of the cluster bootstrapper that will set up the kubernetes cluster. (default "kubeadm") -h, --help help for minikube --log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0) --log_dir string If non-empty, write log files in this directory --logtostderr log to standard error instead of files -p, --profile string The name of the minikube VM being used. This can be modified to allow for multiple minikube instances to be run independently (default "minikube") --stderrthreshold severity logs at or above this threshold go to stderr (default 2) -v, --v Level log level for V logs --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging Use "minikube [command] --help" for more information about a command.
[docker@localhost ~]$ minikube ip 192.168.58.2
kubectl get nodes -o jsonpath='{.items[*].status.addresses[].address}'
minikube start --registry-mirror=https://registry.docker-cn.com minikube start --image-mirror-country=cn --registry-mirror="https://docker.mirrors.ustc.edu.cn" --insecure-registry="127.0.0.1:5000" minikube start --image-mirror-country=cn --registry-mirror="https://docker.mirrors.ustc.edu.cn" --insecure-registry="192.168.0.0/24"
minikube start --image-mirror-country=cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
# 从阿里云下载 virtualbox 镜像 minikube start --vm-driver='virtualbox' --image-mirror-country cn \ --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.9.0.iso \ --registry-mirror=https://docker.mirrors.ustc.edu.cn minikube start --vm-driver=virtualbox \ --image-mirror-country cn \ --registry-mirror=https://docker.mirrors.ustc.edu.cn \ --image-repository=registry.aliyuncs.com/google_containers \ --insecure-registry=192.168.0.10:5000 //访问宿主机的私有docker仓库
minikube start --extra-config="kubelet.allowed-unsafe-sysctls=kernel.msg*,net.core.somaxconn".
minikube start --container-runtime=cri-o --vm-driver=none
启动演示
iMac:~ neo$ minikube start --container-runtime=cri-o 😄 Darwin 10.13.6 上的 minikube v1.15.0 🆕 Kubernetes 1.19.4 is now available. If you would like to upgrade, specify: --kubernetes-version=v1.19.4 ✨ 根据现有的配置文件使用 hyperkit 驱动程序 👍 Starting control plane node minikube in cluster minikube 🔄 Restarting existing hyperkit VM for "minikube" ... 🎁 正在 CRI-O 1.17.3 中准备 Kubernetes v1.19.2… 🔗 Configuring bridge CNI (Container Networking Interface) ... 🔎 Verifying Kubernetes components... 🌟 Enabled addons: storage-provisioner, dashboard, default-storageclass 🏄 Done! kubectl is now configured to use "minikube" cluster and "" namespace by default
[root@localhost ~]# minikube stop Stopping local Kubernetes cluster... Machine stopped.
neo@MacBook-Pro-Neo ~ % minikube docker-env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.64.3:2376" export DOCKER_CERT_PATH="/Users/neo/.minikube/certs" export MINIKUBE_ACTIVE_DOCKERD="minikube" # To point your shell to minikube's docker-daemon, run: # eval $(minikube -p minikube docker-env)
设置环境变量
# eval $(minikube docker-env) # eval $(minikube -p minikube docker-env)
neo@MacBook-Pro-Neo ~ % minikube ssh _ _ _ _ ( ) ( ) ___ ___ (_) ___ (_)| |/') _ _ | |_ __ /' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\ | ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/ (_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____) $
# cache a image into $HOME/.minikube/cache/images $ minikube cache add ubuntu:16.04 $ minikube cache add redis:3 # list cached images $ minikube cache list redis:3 ubuntu:16.04 # delete cached images $ minikube cache delete ubuntu:16.04 $ minikube cache delete $(minikube cache list)
Dashboard是基于Web的Kubernetes管理界面。使用下面的命令启动:
minikube dashboard
查询控制面板访问地址
$ minikube dashboard --url http://192.168.3.14:30000
列出所有服务
Neo-iMac:~ neo$ minikube service list |----------------------|------------------------------------|--------------|-----| | NAMESPACE | NAME | TARGET PORT | URL | |----------------------|------------------------------------|--------------|-----| | default | kubernetes | No node port | | default | nginx | 80 | | | ingress-nginx | ingress-nginx-controller | http/80 | | | | | https/443 | | | ingress-nginx | ingress-nginx-controller-admission | No node port | | kube-system | kube-dns | No node port | | kubernetes-dashboard | dashboard-metrics-scraper | No node port | | kubernetes-dashboard | kubernetes-dashboard | No node port | |----------------------|------------------------------------|--------------|-----|
查看指定服务
Neo-iMac:~ neo$ minikube service nginx |-----------|-------|-------------|---------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|-------|-------------|---------------------------| | default | nginx | 80 | http://192.168.49.2:30330 | |-----------|-------|-------------|---------------------------| 🏃 Starting tunnel for service nginx. |-----------|-------|-------------|------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|-------|-------------|------------------------| | default | nginx | | http://127.0.0.1:55815 | |-----------|-------|-------------|------------------------| 🎉 Opening service default/nginx in default browser... ❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
查看服务的网址
[root@localhost ~]# minikube service hello-minikube --url http://172.16.0.121:30436
minikube docker-env
Neo-iMac:~ neo$ minikube docker-env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://127.0.0.1:54734" export DOCKER_CERT_PATH="/Users/neo/.minikube/certs" export MINIKUBE_ACTIVE_DOCKERD="minikube" # To point your shell to minikube's docker-daemon, run: # eval $(minikube -p minikube docker-env)
minikube profile demo minikube start -p demo --memory=8192 --cpus=6 --disk-size=50g
iMac:registry neo$ minikube addons list |-----------------------------|----------|--------------| | ADDON NAME | PROFILE | STATUS | |-----------------------------|----------|--------------| | ambassador | minikube | disabled | | dashboard | minikube | enabled ✅ | | default-storageclass | minikube | enabled ✅ | | efk | minikube | disabled | | freshpod | minikube | disabled | | gcp-auth | minikube | disabled | | gvisor | minikube | disabled | | helm-tiller | minikube | disabled | | ingress | minikube | disabled | | ingress-dns | minikube | disabled | | istio | minikube | disabled | | istio-provisioner | minikube | disabled | | kubevirt | minikube | disabled | | logviewer | minikube | disabled | | metallb | minikube | disabled | | metrics-server | minikube | disabled | | nvidia-driver-installer | minikube | disabled | | nvidia-gpu-device-plugin | minikube | disabled | | olm | minikube | disabled | | pod-security-policy | minikube | disabled | | registry | minikube | disabled | | registry-aliases | minikube | disabled | | registry-creds | minikube | disabled | | storage-provisioner | minikube | enabled ✅ | | storage-provisioner-gluster | minikube | disabled | |-----------------------------|----------|--------------|
minikube addons enable heapster minikube addons enable ingress
启用 WebUI
[root@localhost ~]# minikube addons enable dashboard dashboard was successfully enabled [root@localhost ~]# minikube addons list | grep dashboard - dashboard: enabled
[root@localhost ~]# minikube addons list - addon-manager: enabled - dashboard: enabled - default-storageclass: enabled - efk: disabled - freshpod: disabled - gvisor: disabled - heapster: disabled - ingress: disabled - kube-dns: disabled - metrics-server: disabled - nvidia-driver-installer: disabled - nvidia-gpu-device-plugin: disabled - registry: disabled - registry-creds: disabled - storage-provisioner: enabled - storage-provisioner-gluster: disabled
Neo-iMac:~ neo$ minikube addons enable dashboard ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-scraper:v1.0.7 ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/dashboard:v2.3.1 💡 Some dashboard features require the metrics-server addon. To enable all features please run: minikube addons enable metrics-server 🌟 The 'dashboard' addon is enabled
Neo-iMac:~ neo$ minikube dashboard 🤔 Verifying dashboard health ... 🚀 Launching proxy ... 🤔 Verifying proxy health ... 🎉 Opening http://127.0.0.1:62433/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
# enable the registry addon $ minikube addons enable registry $ minikube start # use the minikube docker daemon from the host $ eval $(minikube docker-env) # get the ip of the registry endpoint $ kubectl -n kube-system get svc registry -o jsonpath="{.spec.clusterIP}" 10.0.0.240
{ "insecure-registries" : ["10.0.0.240"] }
$ minikube ssh $ docker pull busybox $ docker tag busybox 10.0.0.240/busybox # or # build and push to insecure registry $ docker build -t 10.0.0.240/busybox . $ docker push 10.0.0.240/busybox
Neo-iMac:~ neo$ minikube addons enable ingress 💡 After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "127.0.0.1" ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1 ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1 ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.0.4 🔎 Verifying ingress addon... 🌟 The 'ingress' addon is enabled
运行一个简单的demo
运行 nginx 服务 kubectl run nginx --image=nginx --port=80 暴露服务 kubectl expose deployment nginx --port=80 --target-port=80 创建ingress yaml 定义 ingress.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: nginx spec: rules: - host: www.netkiller.cn http: paths: - path: / backend: serviceName: nginx servicePort: 80 运行 kubectl apply -f ingress.yaml 配置本机host获取minikube ip [docker@localhost ~]$ minikube ip 192.168.58.2 配置 /etc/hosts 文件 192.168.58.2 www.netkiller.cn
访问 http://www.netkiller.cn
--vm-driver=none 不支持 ssh
[root@localhost ~]# minikube ssh 'none' driver does not support 'minikube ssh' command
neo@MacBook-Pro-Neo ~ % minikube image ls registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2 registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-scraper:v1.0.4 registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.20.7 registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.20.7 registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.20.7 registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.20.7 registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.13-0 registry.cn-hangzhou.aliyuncs.com/google_containers/dashboard:v2.1.0 registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.7.0 docker.io/netkiller/flask:latest
neo@MacBook-Pro-Neo ~ % minikube kubectl -- get pods -A > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s > kubectl: 44.08 MiB / 44.08 MiB [--------------] 100.00% 5.30 MiB p/s 8.5s NAMESPACE NAME READY STATUS RESTARTS AGE ingress-nginx ingress-nginx-admission-create-vzk2b 0/1 ImagePullBackOff 0 118d ingress-nginx ingress-nginx-admission-patch-65b85 0/1 ImagePullBackOff 0 118d ingress-nginx ingress-nginx-controller-7f79776f95-ncqkn 0/1 ContainerCreating 0 118d kube-system coredns-54d67798b7-cnjgw 1/1 Running 2 121d kube-system etcd-minikube 1/1 Running 2 121d kube-system kube-apiserver-minikube 1/1 Running 2 121d kube-system kube-controller-manager-minikube 1/1 Running 2 121d kube-system kube-proxy-tr8fd 1/1 Running 2 121d kube-system kube-scheduler-minikube 1/1 Running 2 121d kube-system storage-provisioner 1/1 Running 2 121d