美文网首页
Kubernetes:13.kubectl expose

Kubernetes:13.kubectl expose

作者: 小六的昵称已被使用 | 来源:发表于2019-08-12 16:23 被阅读0次

    语法

    [15:09:51 root@ceshi-01 ~ $]kubectl expose --help
    Expose a resource as a new Kubernetes service.
    将资源公开为新的 Kubernetes 服务
    
    Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port.
    A deployment or replica set will be exposed as a service only if its selector is convertible to a selector that service supports, i.e. when the selector contains only the matchLabels component. 
    Note that if no port is specified via --port and the exposed resource has multiple ports, all will be re-used by the new service. Also if no labels are specified, the new service will re-use the labels from the resource it exposes.
    
    可能的资源包括(不区分大大小写)
        pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs)
    
    Examples:示例
      # Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
      # 为 replicated nginx 创建服务
      # 并将容器的80端口暴露为8000
      kubectl expose rc nginx --port=80 --target-port=800
    
      # Create a service for a replication controller identified by type and name specified in "nginx-controller.yaml",
        which serves on port 80 and connects to the containers on port 8000.
      # 使用 nginx-controller.yaml 文件件中指定的类型和名称标识的复制控制器创建服务
      # 并将容器内的80端口暴露为8000
      kubectl expose -f nginx-controller.yaml --port=80 --target-port=8000
    
      # Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
      # 从名称为 valid-pod 的 pod 创建一个服务
      # 这个服务的端口为444,并且名称为 frontend
      kubectl expose pod valid-pod --port=444 --name=frontend
    
      # Create a second service based on the above service, exposing the container port 8443 as port 443 with the name "nginx-https"
      # 根据上述服务创建第二项服务
      # 服务名称为:nginx-https
      # 将 443 端口暴露为 8443
      kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
    
      # Create a service for a replicated streaming application on port 4100 balancing UDP traffic and named 'video-stream'.
      # 
      kubectl expose rc streamer --port=4100 --protocol=UDP --name=video-stream
    
      # Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000.
      # 使用 nginx 的副本集创建服务
      kubectl expose rs nginx --port=80 --target-port=8000
    
      # Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000.
      # 使用 nginx deployment 创建一个服务
      kubectl expose deployment nginx --port=80 --target-port=8000
    
    Options:选项
          --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. 
                                              如果为true,则在模板中缺少字段或映射键时忽略模板中的任何错误。
                                              Only applies to golang and jsonpath output formats.
                                              仅适用于golang和jsonpath输出格式。
          --cluster-ip='': ClusterIP to be assigned to the service. Leave empty to auto-allocate, or set to 'None' to create a headless service.
                           要分配给服务的ClusterIP。 保留为空以自动分配,或设置为“无”以创建无头服务。
          --dry-run=false: If true, only print the object that would be sent, without sending it.
                           如果为true,则仅打印将要发送的对象,而不发送它。
          --external-ip='': Additional external IP address (not managed by Kubernetes) to accept for the service.
                            额外的外部IP地址(不由Kubernetes管理)接受服务。
                            If this IP is routed to a node, the service can be accessed by this IP in addition to its generated service IP.
                            如果此IP路由到节点,则除了生成的服务IP之外,该IP还可以访问该服务。
      -f, --filename=[]: Filename, directory, or URL to files identifying the resource to expose a service
                         标识公开服务的资源的文件的文件名,目录或URL
          --generator='service/v2': 使用 generator 的名称. 这里有 2 个 generators: 'service/v1' 和 'service/v2'.
    为一个不同地方是服务端口在 v1 的情况下叫 'default', 如果在 v2 中没有指定名称.
    默认的名称是 'service/v2'.
      -k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
                          处理kustomization目录。 该标志不能与-f或-R一起使用。
      -l, --labels='': Labels to apply to the service created by this call.
                       要应用于此调用创建的服务的标签。
          --load-balancer-ip='': IP to assign to the LoadBalancer. If empty, an ephemeral IP will be created and used (cloud-provider specific).
                                 要分配给LoadBalancer的IP。 如果为空,将创建并使用临时IP(特定于云提供商)。
          --name='': 名称为最新创建的对象.
      -o, --output='': Output format. One of:
                       输出格式。
    json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
          --overrides='': An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object.
                          生成的对象的内联JSON覆盖。 如果这是非空的,则用于覆盖生成的对象。
                          Requires that the object supply a valid apiVersion field.
                          要求对象提供有效的apiVersion字段。
          --port='': 服务的端口应该被指定. 如果没有指定, 从被创建的资源中复制
          --protocol='': 创建 service 的时候伴随着一个网络协议被创建. 默认是 'TCP'.
          --record=false: Record current kubectl command in the resource annotation. If set to false, do not record the command.
                          在资源注释中记录当前kubectl命令。 如果设置为false,请不要记录该命令
                          If set to true, record the command.
                          如果设置为true,则记录该命令。
                          If not set, default to updating the existing annotation value only if one already exists.
                          如果未设置,则默认仅在已存在的情况下更新现有注释值。
      -R, --recursive=false: Process the directory used in -f, --filename recursively. 
                             递归方式处理
                             Useful when you want to manage related manifests organized within the same directory.
                             当您想要管理在同一目录中组织的相关清单时很有用。
          --save-config=false: If true, the configuration of current object will be saved in its annotation. 
                               如果为true,则当前对象的配置将保存在其注释中。
                               Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
                               否则,注释将保持不变。 如果要在将来对此对象执行kubectl apply,此标志非常有用。
          --selector='': A label selector to use for this service. Only equality-based selector requirements are supported. 
                         用于此服务的标签选择器。 仅支持基于等同的选择器要求。
                         If empty (the default) infer the selector from the replication controller or replica set.)
                         如果为空(默认值),则从复制控制器或副本集推断选择器。)
          --session-affinity='': If non-empty, set the session affinity for the service to this; legal values: 'None', 'ClientIP'
                                 如果非空,请将服务的会话亲缘关系设置为this; 法律价值观:'无','ClientIP'
          --target-port='': Name or number for the port on the container that the service should direct traffic to.
                            服务应将流量定向到的容器上的端口的名称或编号。
    Optional.
          --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. 
                         模板字符串或模板文件的路径,在-o = go-template,-o = go-template-file时使用。
                         The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
                         模板格式是golang模板[http://golang.org/pkg/text/template/#pkg-overview]。
          --type='': Type for this service: ClusterIP, NodePort, LoadBalancer, or ExternalName. Default is 'ClusterIP'.
                     此服务的类型:ClusterIP,NodePort,LoadBalancer或ExternalName。 默认为'ClusterIP'。
    
    Usage:
      kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name]
    [--name=name] [--external-ip=external-ip-of-service] [--type=type] [options]
    
    Use "kubectl options" for a list of global command-line options (applies to all commands).
    

    相关文章

      网友评论

          本文标题:Kubernetes:13.kubectl expose

          本文链接:https://www.haomeiwen.com/subject/pzjujctx.html