diff --git a/docs/kubectl.md b/docs/kubectl.md index 61d82e1649..df39769f36 100644 --- a/docs/kubectl.md +++ b/docs/kubectl.md @@ -394,11 +394,8 @@ Additional help topics: kubectl rollingupdate Perform a rolling update of the given ReplicationController kubectl resize Set a new size for a resizable resource (currently only Replication Controllers) kubectl run-container Run a particular image on the cluster. -<<<<<<< HEAD kubectl stop Gracefully shutdown a resource -======= kubectl expose Take a replicated application and expose it as Kubernetes Service ->>>>>>> Add a service generator and a command to easily expose services. Use "kubectl help [command]" for more information about that command. ``` @@ -920,6 +917,7 @@ Usage: --image="": The image for the container you wish to run. --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. --kubeconfig="": Path to the kubeconfig file to use for CLI requests. + -l, --labels="": Labels to apply to the pod(s) created by this call to run-container. --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace --log_dir=: If non-empty, write log files in this directory --log_flush_frequency=5s: Maximum number of seconds between log flushes @@ -945,7 +943,6 @@ Usage: ``` -<<<<<<< HEAD #### stop Gracefully shutdown a resource @@ -955,7 +952,40 @@ If the resource is resizable it will be resized to 0 before deletion. Examples: $ kubectl stop replicationcontroller foo foo stopped -======= + + +Usage: +``` + kubectl stop [flags] + + Available Flags: + --alsologtostderr=false: log to standard error as well as files + --api-version="": The API version to use when talking to the server + -a, --auth-path="": Path to the auth info file. If missing, prompt the user. Only used if using https. + --certificate-authority="": Path to a cert. file for the certificate authority. + --client-certificate="": Path to a client key file for TLS. + --client-key="": Path to a client key file for TLS. + --cluster="": The name of the kubeconfig cluster to use + --context="": The name of the kubeconfig context to use + --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. + --kubeconfig="": Path to the kubeconfig file to use for CLI requests. + --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace + --log_dir=: If non-empty, write log files in this directory + --log_flush_frequency=5s: Maximum number of seconds between log flushes + --logtostderr=true: log to standard error instead of files + --match-server-version=false: Require server version to match client version + --namespace="": If present, the namespace scope for this CLI request. + --ns-path="": Path to the namespace info file that holds the namespace context to use for CLI requests. + -s, --server="": The address of the Kubernetes API server + --stderrthreshold=2: logs at or above this threshold go to stderr + --token="": Bearer token for authentication to the API server. + --user="": The name of the kubeconfig user to use + --v=0: log level for V logs + --validate=false: If true, use a schema to validate the input before sending it + --vmodule=: comma-separated list of pattern=N settings for file-filtered logging + +``` + #### expose Take a replicated application and expose it as Kubernetes Service. @@ -968,16 +998,11 @@ $ kubectl expose nginx --port=80 --container-port=8000 $ kubectl expose streamer --port=4100 --protocol=udp --service-name=video-stream ->>>>>>> Add a service generator and a command to easily expose services. Usage: ``` -<<<<<<< HEAD - kubectl stop [flags] -======= kubectl expose --port= [--protocol=TCP|UDP] [--container-port=] [--service-name=] [--public-ip=] [--create-external-load-balancer] [flags] ->>>>>>> Add a service generator and a command to easily expose services. Available Flags: --alsologtostderr=false: log to standard error as well as files @@ -987,11 +1012,6 @@ Usage: --client-certificate="": Path to a client key file for TLS. --client-key="": Path to a client key file for TLS. --cluster="": The name of the kubeconfig cluster to use -<<<<<<< HEAD - --context="": The name of the kubeconfig context to use - --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. - --kubeconfig="": Path to the kubeconfig file to use for CLI requests. -======= --container-port="": Name or number for the port on the container that the service should direct traffic to. Optional. --context="": The name of the kubeconfig context to use --create-external-load-balancer=false: If true, create an external load balancer for this service. Implementation is cloud provider dependent. Default false @@ -1000,32 +1020,25 @@ Usage: -h, --help=false: help for expose --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure. --kubeconfig="": Path to the kubeconfig file to use for CLI requests. - -l, --labels="": Labels to apply to the pod(s) created by this call to run. ->>>>>>> Add a service generator and a command to easily expose services. --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace --log_dir=: If non-empty, write log files in this directory --log_flush_frequency=5s: Maximum number of seconds between log flushes --logtostderr=true: log to standard error instead of files --match-server-version=false: Require server version to match client version -<<<<<<< HEAD --namespace="": If present, the namespace scope for this CLI request. - --ns-path="": Path to the namespace info file that holds the namespace context to use for CLI requests. - -s, --server="": The address of the Kubernetes API server - --stderrthreshold=2: logs at or above this threshold go to stderr -======= - -n, --namespace="": If present, the namespace scope for this CLI request. --no-headers=false: When using the default output, don't print headers - --ns-path="/home/username/.kubernetes_ns": Path to the namespace info file that holds the namespace context to use for CLI requests. + --ns-path="": Path to the namespace info file that holds the namespace context to use for CLI requests. -o, --output="": Output format: json|yaml|template|templatefile --output-version="": Output the formatted object with the given version (default api-version) --overrides="": An inline JSON override for the generated object. If this is non-empty, it is parsed used to override the generated object. Requires that the object supply a valid apiVersion field. --port=-1: The port that the service should serve on. Required. --protocol="TCP": The network protocol for the service you want to be created. Default 'tcp' + --public-ip="": Name of a public ip address to set for the service. The service will be assigned this IP in addition to its generated service IP. + --selector="": A label selector to use for this service. If empty (the default) infer the selector from the replication controller -s, --server="": The address of the Kubernetes API server - --service-name="": The name for the newly create service. + --service-name="": The name for the newly created service. --stderrthreshold=2: logs at or above this threshold go to stderr -t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. ->>>>>>> Add a service generator and a command to easily expose services. --token="": Bearer token for authentication to the API server. --user="": The name of the kubeconfig user to use --v=0: log level for V logs diff --git a/pkg/api/types.go b/pkg/api/types.go index 8202b1e68e..a800631a8c 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -654,6 +654,7 @@ type ServiceSpec struct { PublicIPs []string `json:"publicIPs,omitempty"` // ContainerPort is the name of the port on the container to direct traffic to. + // Optional, if unspecified use the first port on the container. ContainerPort util.IntOrString `json:"containerPort,omitempty"` // Optional: Supports "ClientIP" and "None". Used to maintain session affinity. diff --git a/pkg/kubectl/cmd/expose.go b/pkg/kubectl/cmd/expose.go index 10ef362e53..2a7bda235d 100644 --- a/pkg/kubectl/cmd/expose.go +++ b/pkg/kubectl/cmd/expose.go @@ -46,7 +46,8 @@ $ kubectl expose streamer --port=4100 --protocol=udp --service-name=video-stream usageError(cmd, " is required for expose") } - namespace := GetKubeNamespace(cmd) + namespace, err := f.DefaultNamespace(cmd) + checkErr(err) client, err := f.Client(cmd) checkErr(err) @@ -68,7 +69,9 @@ $ kubectl expose streamer --port=4100 --protocol=udp --service-name=video-stream } else { params["name"] = GetFlagString(cmd, "service-name") } - params["labels"] = kubectl.MakeLabels(rc.Spec.Selector) + if _, found := params["selector"]; !found { + params["selector"] = kubectl.MakeLabels(rc.Spec.Selector) + } if GetFlagBool(cmd, "create-external-load-balancer") { params["create-external-load-balancer"] = "true" } @@ -99,10 +102,11 @@ $ kubectl expose streamer --port=4100 --protocol=udp --service-name=video-stream cmd.Flags().String("protocol", "TCP", "The network protocol for the service you want to be created. Default 'tcp'") cmd.Flags().Int("port", -1, "The port that the service should serve on. Required.") cmd.Flags().Bool("create-external-load-balancer", false, "If true, create an external load balancer for this service. Implementation is cloud provider dependent. Default false") - cmd.Flags().StringP("labels", "l", "", "Labels to apply to the pod(s) created by this call to run.") + cmd.Flags().String("selector", "", "A label selector to use for this service. If empty (the default) infer the selector from the replication controller") cmd.Flags().Bool("dry-run", false, "If true, only print the object that would be sent, don't actually do anything") cmd.Flags().String("container-port", "", "Name or number for the port on the container that the service should direct traffic to. Optional.") + cmd.Flags().String("public-ip", "", "Name of a public ip address to set for the service. The service will be assigned this IP in addition to its generated service IP.") cmd.Flags().String("overrides", "", "An inline JSON override for the generated object. If this is non-empty, it is parsed used to override the generated object. Requires that the object supply a valid apiVersion field.") - cmd.Flags().String("service-name", "", "The name for the newly create service.") + cmd.Flags().String("service-name", "", "The name for the newly created service.") return cmd } diff --git a/pkg/kubectl/cmd/run.go b/pkg/kubectl/cmd/run.go index 5a5b66dc88..09f0195a48 100644 --- a/pkg/kubectl/cmd/run.go +++ b/pkg/kubectl/cmd/run.go @@ -93,5 +93,6 @@ Examples: cmd.Flags().String("public-ip", "", "A public IP address to use for this service.") cmd.Flags().String("overrides", "", "An inline JSON override for the generated object. If this is non-empty, it is parsed used to override the generated object. Requires that the object supply a valid apiVersion field.") cmd.Flags().Int("port", -1, "The port that this container exposes.") + cmd.Flags().StringP("labels", "l", "", "Labels to apply to the pod(s) created by this call to run-container.") return cmd } diff --git a/pkg/kubectl/service.go b/pkg/kubectl/service.go index 29e3886d4d..ce7acf323c 100644 --- a/pkg/kubectl/service.go +++ b/pkg/kubectl/service.go @@ -30,7 +30,7 @@ type ServiceGenerator struct{} func (ServiceGenerator) ParamNames() []GeneratorParam { return []GeneratorParam{ {"name", true}, - {"labels", true}, + {"selector", true}, {"port", true}, {"public-ip", false}, {"create-external-load-balancer", false}, @@ -40,11 +40,11 @@ func (ServiceGenerator) ParamNames() []GeneratorParam { } func (ServiceGenerator) Generate(params map[string]string) (runtime.Object, error) { - labelString, found := params["labels"] - if !found || len(labelString) == 0 { - return nil, fmt.Errorf("'labels' is a required parameter.") + selectorString, found := params["selector"] + if !found || len(selectorString) == 0 { + return nil, fmt.Errorf("'selector' is a required parameter.") } - labels := ParseLabels(labelString) + selector := ParseLabels(selectorString) name, found := params["name"] if !found { return nil, fmt.Errorf("'name' is a required parameter.") @@ -55,13 +55,12 @@ func (ServiceGenerator) Generate(params map[string]string) (runtime.Object, erro } service := api.Service{ ObjectMeta: api.ObjectMeta{ - Name: name, - Labels: labels, + Name: name, }, Spec: api.ServiceSpec{ Port: port, Protocol: api.Protocol(params["protocol"]), - Selector: labels, + Selector: selector, }, } containerPort, found := params["container-port"]