Kubernetes kubectl create service externalname 命令详解

kubectl create service externalname

创建指定Service名的ExternalName。

语法

$ externalname NAME --external-name external.name [--dry-run]

示例

创建Service名为my-ns的ExternalName

kubectl create service externalname my-ns --external-name bar.com

Flags

Name Shorthand Default Usage
allow-missing-template-keys true If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
dry-run false If true, only print the object that would be sent, without sending it.
external-name external name of service
generator service-externalname/v1 The name of the API generator to use.
no-headers false When using the default or custom-column output format, don't print headers (default print headers).
output o Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
output-version DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').
save-config false If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
schema-cache-dir ~/.kube/schema If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
show-all a false When printing, show all resources (default hide terminated pods.)
show-labels false When printing, show all labels as the last column (default hide labels column)
sort-by If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
tcp [] Port pairs can be specified as ':'.
template Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
validate true If true, use a schema to validate the input before sending it
K8S中文社区微信公众号

Kubernetes kubectl create service clusterip 命令详解

kubectl create service clusterip

创建具有指定Service名的clusterIP。

语法

$ clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run]

示例

创建Service名为my-cs为的clusterIP

kubectl create service clusterip my-cs --tcp=5678:8080

创建Service名为my-cs的clusterIP(headless模式)

kubectl create service clusterip my-cs --clusterip="None"

Flags

Name Shorthand Default Usage
allow-missing-template-keys true If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
clusterip Assign your own ClusterIP or set to 'None' for a 'headless' service (no loadbalancing).
dry-run false If true, only print the object that would be sent, without sending it.
generator service-clusterip/v1 The name of the API generator to use.
no-headers false When using the default or custom-column output format, don't print headers (default print headers).
output o Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
output-version DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').
save-config false If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
schema-cache-dir ~/.kube/schema If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
show-all a false When printing, show all resources (default hide terminated pods.)
show-labels false When printing, show all labels as the last column (default hide labels column)
sort-by If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
tcp [] Port pairs can be specified as ':'.
template Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
validate true If true, use a schema to validate the input before sending it
K8S中文社区微信公众号

Kubernetes kubectl create secret tls 命令详解

create secret tls

从给定的(public/private)公钥/私钥对创建TLS secret 。

公共密钥证书必须是.PEM编码并匹配指定的私钥。

语法

$ tls NAME --cert=path/to/cert/file --key=path/to/key/file [--dry-run]

示例

使用指定的key创建名为tls-secret的TLS secret :

kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key

Flags

Name Shorthand Default Usage
allow-missing-template-keys true If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
cert Path to PEM encoded public key certificate.
dry-run false If true, only print the object that would be sent, without sending it.
generator secret-for-tls/v1 The name of the API generator to use.
key Path to private key associated with given certificate.
no-headers false When using the default or custom-column output format, don't print headers (default print headers).
output o Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
output-version DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').
save-config false If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
schema-cache-dir ~/.kube/schema If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
show-all a false When printing, show all resources (default hide terminated pods.)
show-labels false When printing, show all labels as the last column (default hide labels column)
sort-by If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
template Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
validate true If true, use a schema to validate the input before sending it
K8S中文社区微信公众号

Kubernetes kubectl create secret generic 命令详解

kubectl create secret generic

根据配置文件、目录或指定的literal-value创建secret。

secret可以保存为一个或多个key/value信息。

当基于配置文件创建secret时,key将默认为文件的基础名称,value默认为文件内容。如果基本名称的key无效,则可以指定另一个key。

当基于目录创建secret时,key还是文件的基础名称,目录中有效的key的每个文件都被打包到secret中,除了常规文件之外的任何目录条目都被忽略(例如subdirectories, symlinks, devices, pipes, etc)。

语法

$ generic NAME [--type=string] [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run]

示例

使用指定的keys创建一个名为my-secret的secret

kubectl create secret generic my-secret --from-file=ssh-privatekey=~/.ssh/id_rsa --from-file=ssh-publickey=~/.ssh/id_rsa.pub

用key1 = supersecret和key2 = topsecret创建一个名为my-secret的secret

kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret

从env文件创建名为my-secret的secret

kubectl create secret generic my-secret --from-env-file=path/to/bar.env

Flags

Name Shorthand Default Usage
allow-missing-template-keys true If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
dry-run false If true, only print the object that would be sent, without sending it.
from-env-file Specify the path to a file to read lines of key=val pairs to create a secret (i.e. a Docker .env file).
from-file [] Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.
from-literal [] Specify a key and literal value to insert in secret (i.e. mykey=somevalue)
generator secret/v1 The name of the API generator to use.
no-headers false When using the default or custom-column output format, don't print headers (default print headers).
output o Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
output-version DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').
save-config false If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
schema-cache-dir ~/.kube/schema If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
show-all a false When printing, show all resources (default hide terminated pods.)
show-labels false When printing, show all labels as the last column (default hide labels column)
sort-by If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
template Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
type The type of secret to create
validate true If true, use a schema to validate the input before sending it
K8S中文社区微信公众号

Kubernetes kubectl create secret docker-registry 命令详解

kubectl create secret docker-registry

创建与Docker registries一起使用的secret。

Dockercfg secrets用于对Docker registries进行安全认证。

当使用Docker命令push镜像时,可以进行Docker registries认证

$ docker login DOCKER_REGISTRY_SERVER --username=DOCKER_USER --password=DOCKER_PASSWORD --email=DOCKER_EMAIL'.

这时会产生一个 ~/.dockercfg 文件,在“docker push”和“docker pull”命令时,此文件用于registries进行认证。

在创建应用时,当Node节点从私有仓库Pull镜像时,需要有相应凭证,才能使用私有Docker仓库。我们可以通过创建dockercfg secret并添加到service account来实现。

语法

$ docker-registry NAME --docker-username=user --docker-password=password --docker-email=email [--docker-server=string] [--from-literal=key1=value1] [--dry-run]

示例

如果没有.dockercfg 文件,则可以使用以下命令创建dockercfg secret:

kubectl create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL

Flags

Name Shorthand Default Usage
allow-missing-template-keys true If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
docker-email Email for Docker registry
docker-password Password for Docker registry authentication
docker-server https://index.docker.io/v1/ Server location for Docker registry
docker-username Username for Docker registry authentication
dry-run false If true, only print the object that would be sent, without sending it.
generator secret-for-docker-registry/v1 The name of the API generator to use.
include-extended-apis true If true, include definitions of new APIs via calls to the API server. [default true]
no-headers false When using the default or custom-column output format, don't print headers (default print headers).
output o Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].
output-version DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob').
save-config false If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
schema-cache-dir ~/.kube/schema If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
show-all a false When printing, show all resources (default hide terminated pods.)
show-labels false When printing, show all labels as the last column (default hide labels column)
sort-by If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string.
template Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
validate true If true, use a schema to validate the input before sending it
K8S中文社区微信公众号