1. minikube stop

停止一个本地的 Kubernetes 集群

该命令会停止 VM 虚拟机或容器,以此来停止一个 Kubernetes集群,但是会完整的保留数据。

被停止的 Kubernetes 可以被 start 命令重新启动。

minikube stop [flags]

1.1. 选项

1.1.1. 命令选项

      --all                   Set flag to stop all profiles (clusters)
      --cancel-scheduled      cancel any existing scheduled stop requests
      --keep-context-active   keep the kube-context active after cluster is stopped. Defaults to false.
  -o, --output string         Format to print stdout in. Options include: [text,json] (default "text")
      --schedule duration     Set flag to stop cluster after a set amount of time (e.g. --schedule=5m)

1.1.2. 从父命令继承的选项

      --add_dir_header                   If true, adds the file directory to the header of the log messages
      --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                             
      --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
      --log_file string                  If non-empty, use this log file
      --log_file_max_size uint           Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
      --logtostderr                      log to standard error instead of files
      --one_output                       If true, only write logs to their native severity level (vs also writing to each lower severity level)
  -p, --profile string                   The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently. (default "minikube")
      --skip_headers                     If true, avoid header prefixes in the log messages
      --skip_log_headers                 If true, avoid headers when opening log files
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
      --user string                      Specifies the user executing the operation. Useful for auditing operations executed by 3rd party tools. Defaults to the operating system username.
  -v, --v Level                          number for the log level verbosity
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

1.1.3. 选项说明

选项 默认值 描述
--all 该选项会停止所有的配置关联的 k8s 集群
  --cancel-scheduled      cancel any existing scheduled stop requests
  --keep-context-active   keep the kube-context active after cluster is stopped. Defaults to false.

-o, --output string Format to print stdout in. Options include: [text,json] (default "text") --schedule duration Set flag to stop cluster after a set amount of time (e.g. --schedule=5m)

1.2. 示例

1.2.1. 停止并启动一个 Kubernetes 集群

将一个运行中的 Kubernetes 集群 stop 停止掉

[minikube@localhost ~]$ minikube stop
✋  Stopping node "k8s2"  ...
🛑  Powering off "k8s2" via SSH ...
✋  Stopping node "k8s2-m02"  ...
🛑  Powering off "k8s2-m02" via SSH ...
🛑  2 nodes stopped.

集群被停止后,虚拟机或容器就是 stop 的状态,不能提供服务

[minikube@localhost ~]$ minikube status
k8s2
type: Control Plane
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped

k8s2-m02
type: Worker
host: Stopped
kubelet: Stopped

被停止的 Kubernetes 集群是无法正常访问和使用,但是数据被完整的保留。如果有需要,就可以通过 start 命令重新将集群启动

[minikube@localhost ~]$ minikube start
😄  [k8s2] minikube v1.24.0 on Centos 8.0.1905 (amd64)
✨  Using the docker driver based on existing profile
👍  Starting control plane node k8s2 in cluster k8s2
🚜  Pulling base image ...
🎉  minikube 1.25.2 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.25.2
💡  To disable this notice, run: 'minikube config set WantUpdateNotification false'

🔄  Restarting existing docker container for "k8s2" ...
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
🔗  Configuring CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
👍  Starting worker node k8s2-m02 in cluster k8s2
🚜  Pulling base image ...
🔄  Restarting existing docker container for "k8s2-m02" ...
🌐  Found network options:
    ▪ NO_PROXY=192.168.58.2
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
    ▪ env NO_PROXY=192.168.58.2
🔎  Verifying Kubernetes components...

❗  /usr/bin/kubectl is version 1.18.0, which may have incompatibilites with Kubernetes 1.22.3.
    ▪ Want kubectl v1.22.3? Try 'minikube kubectl -- get pods -A'
🏄  Done! kubectl is now configured to use "k8s2" cluster and "default" namespace by default

重新查看 k8s 集群状态,都已经是 Running 运行的状态

[minikube@localhost ~]$ minikube status
k8s2
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

k8s2-m02
type: Worker
host: Running
kubelet: Running

1.2.2. 停止本机所有的 Kubernetes 集群

通过 --all 选项可以将本机所有的配置管理的集群都 stop 停止掉。

[minikube@localhost ~]$ minikube profile list
|---------|-----------|---------|--------------|------|---------|---------|-------|
| Profile | VM Driver | Runtime |      IP      | Port | Version | Status  | Nodes |
|---------|-----------|---------|--------------|------|---------|---------|-------|
| k8s1    | docker    | docker  | 192.168.49.2 | 8443 | v1.22.3 | Running |     3 |
| k8s2    | docker    | docker  | 192.168.58.2 | 8443 | v1.22.3 | Running |     2 |
|---------|-----------|---------|--------------|------|---------|---------|-------|
[minikube@localhost ~]$ minikube stop --all
✋  Stopping node "k8s1"  ...
🛑  Powering off "k8s1" via SSH ...
✋  Stopping node "k8s1-m02"  ...
🛑  Powering off "k8s1-m02" via SSH ...
✋  Stopping node "k8s1-m03"  ...
🛑  Powering off "k8s1-m03" via SSH ...
✋  Stopping node "k8s2"  ...
🛑  Powering off "k8s2" via SSH ...
✋  Stopping node "k8s2-m02"  ...
🛑  Powering off "k8s2-m02" via SSH ...
🛑  2 nodes stopped.
[minikube@localhost ~]$ minikube profile list
|---------|-----------|---------|--------------|------|---------|---------|-------|
| Profile | VM Driver | Runtime |      IP      | Port | Version | Status  | Nodes |
|---------|-----------|---------|--------------|------|---------|---------|-------|
| k8s1    | docker    | docker  | 192.168.49.2 | 8443 | v1.22.3 | Stopped |     3 |
| k8s2    | docker    | docker  | 192.168.58.2 | 8443 | v1.22.3 | Stopped |     2 |
|---------|-----------|---------|--------------|------|---------|---------|-------|
[minikube@localhost ~]$

minikube 可以全部停止所有集群,但是不支持批量全部启动集群。因此,当我们需要将停止的集群 start 拉起时,需要一一的拉起

[minikube@localhost ~]$ minikube start
😄  [k8s2] minikube v1.24.0 on Centos 8.0.1905 (amd64)
✨  Using the docker driver based on existing profile
👍  Starting control plane node k8s2 in cluster k8s2
🚜  Pulling base image ...
🔄  Restarting existing docker container for "k8s2" ...
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
🔗  Configuring CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
👍  Starting worker node k8s2-m02 in cluster k8s2
🚜  Pulling base image ...
🔄  Restarting existing docker container for "k8s2-m02" ...
🌐  Found network options:
    ▪ NO_PROXY=192.168.58.2
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
    ▪ env NO_PROXY=192.168.58.2
🔎  Verifying Kubernetes components...

❗  /usr/bin/kubectl is version 1.18.0, which may have incompatibilites with Kubernetes 1.22.3.
    ▪ Want kubectl v1.22.3? Try 'minikube kubectl -- get pods -A'
🏄  Done! kubectl is now configured to use "k8s2" cluster and "default" namespace by default
[minikube@localhost ~]$ minikube start -p k8s1
😄  [k8s1] minikube v1.24.0 on Centos 8.0.1905 (amd64)
✨  Using the docker driver based on existing profile
👍  Starting control plane node k8s1 in cluster k8s1
🚜  Pulling base image ...
🔄  Restarting existing docker container for "k8s1" ...
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
🔗  Configuring CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
👍  Starting worker node k8s1-m02 in cluster k8s1
🚜  Pulling base image ...
🔄  Restarting existing docker container for "k8s1-m02" ...
🌐  Found network options:
    ▪ NO_PROXY=192.168.49.2
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
    ▪ env NO_PROXY=192.168.49.2
🔎  Verifying Kubernetes components...
👍  Starting worker node k8s1-m03 in cluster k8s1
🚜  Pulling base image ...
🔄  Restarting existing docker container for "k8s1-m03" ...
🌐  Found network options:
    ▪ NO_PROXY=192.168.49.2,192.168.49.3
🐳  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
    ▪ env NO_PROXY=192.168.49.2
    ▪ env NO_PROXY=192.168.49.2,192.168.49.3
🔎  Verifying Kubernetes components...

❗  /usr/bin/kubectl is version 1.18.0, which may have incompatibilites with Kubernetes 1.22.3.
    ▪ Want kubectl v1.22.3? Try 'minikube kubectl -- get pods -A'
🏄  Done! kubectl is now configured to use "k8s1" cluster and "default" namespace by default
[minikube@localhost ~]$ minikube profile list
|---------|-----------|---------|--------------|------|---------|---------|-------|
| Profile | VM Driver | Runtime |      IP      | Port | Version | Status  | Nodes |
|---------|-----------|---------|--------------|------|---------|---------|-------|
| k8s1    | docker    | docker  | 192.168.49.2 | 8443 | v1.22.3 | Running |     3 |
| k8s2    | docker    | docker  | 192.168.58.2 | 8443 | v1.22.3 | Running |     2 |
|---------|-----------|---------|--------------|------|---------|---------|-------|

这里启动的第一个集群没有指定 -p k8s1 是因为,k8s1 的集群配置设置成默认的了。

Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2022-06-09 23:51:02

results matching ""

    No results matching ""