1. minikube tunnel

连接 Loadbalancer 的服务

tunnel 创建一个路由来访问 LoadBalancer 服务,并 sets their Ingress to their ClusterIP

详细的示例可以参考 https://minikube.sigs.k8s.io/docs/tasks/loadbalancer

minikube tunnel [flags]

1.1. Options

  -c, --cleanup   call with cleanup=true to remove old tunnels (default true)

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.3. 示例

1.3.1. 使用 Loadbalancer 暴露服务

创建一个 Loadbalancer 类型的服务

默认没有启用 minikube tunnel 的情况下,EXTERNAL-IP 字段是 <pending> 状态。即没有正常分配外部访问的 Loadbalancer 类型的 IP 地址

[minikube@localhost ~]$ kubectl  get svc hello-minikube1
NAME              TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
hello-minikube1   LoadBalancer   10.107.220.62   <pending>     8080:30675/TCP   12s

启用 tunnel 需要单独打开一个命令行窗口执行 minikube tunnel,该命令会启动是一个前台进程,需要使用 Ctrl + c 停止进程执行。

[minikube@localhost ~]$ minikube  tunnel
Status:    
    machine: k8s1
    pid: 653033
    route: 10.96.0.0/12 -> 192.168.49.2
    minikube: Running
    services: [hello-minikube1]
    errors: 
        minikube: no errors
        router: no errors
        loadbalancer emulator: no errors

当 tunnle 开启后,再次查看 svc 时,EXTERNAL-IP 字段就可以正常分配 IP 地址

[minikube@localhost ~]$ kubectl  get svc hello-minikube1
NAME              TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
hello-minikube1   LoadBalancer   10.107.220.62   10.107.220.62   8080:30675/TCP   81s

在主机或浏览器中访问 Loadbalancer 的 IP 和服务暴露的端口来访问

[minikube@localhost ~]$ curl 10.107.220.62:8080
CLIENT VALUES:
client_address=192.168.49.2
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://10.107.220.62:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=*/*
host=10.107.220.62:8080
user-agent=curl/7.61.1
BODY:
-no body in request-
Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2022-06-13 09:50:39

results matching ""

    No results matching ""