Kubernetes kubectl Command Overview

Kubernetes cluster management tools to run the command kubectl for.

grammar

kubectl [command] [TYPE] [NAME] [flags]
  • command: Specifies the operation performed by one or more resources
  • TYPE: Specifies the resource type Resource types. Resource types are case-sensitive, you can also specify the singular or plural form of abbreviations
  • Name is case-sensitive, if Name is omitted, all the details of the display resources
  • Command line specified flags will override the default value and any corresponding environment variable

Formatting output format output

All default format kubectl command output is readable in plain text. For more information to be output to the terminal window in a specific format, may be added to kubectl -o -output flags or command supported.

grammar

kubectl [command] [TYPE] [NAME] -o=<output_format>

It supports the following output formats:

Output Format description
-o=custom-columns=spec Use a comma-separated list of columns to print a custom table
-o=custom-columns-file=filename custom columns using the template filename print table file
oh = json API object output JSON format
-o=jsonpath-file=filename Printed by jsonpath filename field expressions defined in the file
-o=name Print only the resource name, other content without printing
-o=wide Plain text output any additional information. For the pod, including node name
o = yaml API object output format YAML
-o=jsonpath=template Print fields defined in jsonpath expression

sort sort

To sort the object list to the output terminal of the window, may be added to kubectl --sort-by flag support command, any number or string specified by using the --sort-by field flag to sort the object to be specified fields, use jsonpath expressions.

$ kubectl [command] [TYPE] [NAME] --sort-by=<jsonpath_exp>
#打印按名称排序的pod列表
$ kubectl get pods --sort-by=.metadata.name

kubectl command Detailed

Options:

      --alsologtostderr[=false]: 同时输出日志到标准错误控制台和文件。
      --api-version="": 和服务端交互使用的API版本。
      --certificate-authority="": 用以进行认证授权的.cert文件路径。
      --client-certificate="": TLS使用的客户端证书路径。
      --client-key="": TLS使用的客户端密钥路径。
      --cluster="": 指定使用的kubeconfig配置文件中的集群名。
      --context="": 指定使用的kubeconfig配置文件中的环境名。
      --insecure-skip-tls-verify[=false]: 如果为true,将不会检查服务器凭证的有效性,这会导致你的HTTPS链接变得不安全。
      --kubeconfig="": 命令行请求使用的配置文件路径。
      --log-backtrace-at=:0: 当日志长度超过定义的行数时,忽略堆栈信息。
      --log-dir="": 如果不为空,将日志文件写入此目录。
      --log-flush-frequency=5s: 刷新日志的最大时间间隔。
      --logtostderr[=true]: 输出日志到标准错误控制台,不输出到文件。
      --match-server-version[=false]: 要求服务端和客户端版本匹配。
      --namespace="": 如果不为空,命令将使用此namespace。
      --password="": API Server进行简单认证使用的密码。
  -s, --server="": Kubernetes API Server的地址和端口号。
      --stderrthreshold=2: 高于此级别的日志将被输出到错误控制台。
      --token="": 认证到API Server使用的令牌。
      --user="": 指定使用的kubeconfig配置文件中的用户名。
      --username="": API Server进行简单认证使用的用户名。
      --v=0: 指定输出日志的级别。
      --vmodule=: 指定输出日志的模块,格式如下:pattern=N,使用逗号分隔。

kubectl run

  • Create and run one or more containers mirroring.
  • Or create a deployment job to manage the container.

grammar:

$ run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]

Example:

# 启动nginx实例。
$ kubectl run nginx --image=nginx
# 启动hazelcast实例,暴露容器端口 5701。
$ kubectl run hazelcast --image=hazelcast --port=5701
# 启动hazelcast实例,在容器中设置环境变量“DNS_DOMAIN = cluster”和“POD_NAMESPACE = default”。
$ kubectl run hazelcast --image=hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"
# 启动nginx实例,设置副本数5。
$ kubectl run nginx --image=nginx --replicas=5
# 运行 Dry  打印相应的API对象而不创建它们。
$ kubectl run nginx --image=nginx --dry-run

kubectl annotate

Update one or more resources Annotations information.

  • Annotations by the key / value components.
  • Annotations The purpose is to store auxiliary data, particularly the data expansion operation by tools and systems, more description here.
  • --Overwrite If true, the existing annotations can be covered, otherwise an error to attempt to cover annotations.
  • If you set --resource-version, the update will use this resource version, otherwise it will use the existing resource version.
  • Support resources include but are not limited to (not sensitive): pods (po), services (svc), replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), resourcequotas (quota) and secrets.
$ kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]

Example:

# 更新pod “foo”,设置其注解description的值为my frontend。
# 如果同一个注解被赋值了多次,只保存最后一次设置的值。
$ kubectl annotate pods foo description='my frontend'

# 更新“pod.json”文件中type和name字段指定的pod的注解。
$ kubectl annotate -f pod.json description='my frontend'

# 更新pod “foo”,设置其注解description的值为my frontend running nginx,已有的值将被覆盖。
$ kubectl annotate --overwrite pods foo description='my frontend running nginx'

# 更新同一namespace下所有的pod。
$ kubectl annotate pods --all description='my frontend running nginx'

# 仅当pod “foo”当前版本为1时,更新其注解
$ kubectl annotate pods foo description='my frontend running nginx' --resource-version=1

# 更新pod “foo”,删除其注解description。
# 不需要--override选项。
$ kubectl annotate pods foo description-

Options:

--all[=false]: 选择namespace中所有指定类型的资源。
-f, --filename=[]: 用来指定待升级资源的文件名,目录名或者URL。
--overwrite[=false]: 如果设置为true,允许覆盖更新注解,否则拒绝更新已存在的注解。
--resource-version="": 如果不为空,仅当资源当前版本和指定版本相同时才能更新注解。仅当更新单个资源时有效。

The remaining options are inherited from the parent command!

kubectl autoscale

Use autoscaler automatic setting of the number of runs in the pod kubernetes cluster (horizontal autostretch).
Designated Deployment, ReplicaSet or ReplicationController, and create a resource has been defined retractor. Use retractor can be automatically increased or decreased in number according to the pod system deployment.

$ autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]

Example:

# 使用 Deployment “foo”设定,使用默认的自动伸缩策略,指定目标CPU使用率,使其Pod数量在2到10之间。
$ kubectl autoscale deployment foo --min=2 --max=10

# 使用RC“foo”设定,使其Pod的数量介于1和5之间,CPU使用率维持在80%。
$ kubectl autoscale rc foo --max=5 --cpu-percent=80

kubectl apply

, The configuration of resources by file name or console input.
Accepts JSON and YAML description file format.

$ kubectl apply -f FILENAME

Example:

# 将pod.json中的配置应用到pod
$ kubectl apply -f ./pod.json

# 将控制台输入的JSON配置应用到Pod
$ cat pod.json | kubectl apply -f -

Options:

  -f, --filename=[]: 包含配置信息的文件名,目录名或者URL。
  -o, --output="": 输出格式,使用“-o name”来输出简短格式(资源类型/资源名)。
      --schema-cache-dir="/tmp/kubectl.schema": 如果不为空,将API schema缓存为指定文件,默认缓存到“/tmp/kubectl.schema”。
      --validate[=true]: 如果为true,在发送到服务端前先使用schema来验证输入。

kubectl attach

Connected to the existing process in a container running.

$ kubectl attach POD -c CONTAINER

Example:

# 获取正在运行中的pod 123456-7890的输出,默认连接到第一个容器
$ kubectl attach 123456-7890

# 获取pod 123456-7890中ruby-container的输出
$ kubectl attach 123456-7890 -c ruby-container date

# 切换到终端模式,将控制台输入发送到pod 123456-7890的ruby-container的“bash”命令,并将其输出到控制台/
# 错误控制台的信息发送回客户端。
$ kubectl attach 123456-7890 -c ruby-container -i -t

Options:

  -c, --container="": 容器名。
  -i, --stdin[=false]: 将控制台输入发送到容器。
  -t, --tty[=false]: 将标准输入控制台作为容器的控制台输入。

kubectl config

Config subcommand used to modify kubeconfig profile, such as "kubectl config set current-context my -context".
Reads the configuration file to the following rules:

  • If --kubeconfig option is specified, then only the specified file is loaded. This option can be set only once, and will not be combined with other files.
  • A list of all files if you set the environment variable $ KUBECONFIG, will use this environment variable specified (using the operating system's default sequence), all files will be merged. When modifying a value, the modified value of the document set. When creating a value, that value will be created in the first file list. If the list of all the files are not present, the last file in the list will be created.
  • If the first two are not set, the $ {HOME} /. Kube / config, and other files are not merged.

kubectl config set-cluster
set up a cluster entry in the kubeconfig profile. If an existing name is specified, incorporating new fields and overwrite the old field.

$ kubectl config set-cluster NAME [--server=server] [--certificate-authority=path/to/certficate/authority] [--api-version=apiversion] [--insecure-skip-tls-verify=true]

Examples

# 仅设置e2e集群项中的server字段,不影响其他字段
$ kubectl config set-cluster e2e --server=https://1.2.3.4

# 向e2e集群项中添加认证鉴权数据
$ kubectl config set-cluster e2e --certificate-authority=~/.kube/e2e/kubernetes.ca.crt

# 取消dev集群项中的证书检查
$ kubectl config set-cluster e2e --insecure-skip-tls-verify=true

Options

      --api-version="": 设置kuebconfig配置文件中集群选项中的api-version。
      --certificate-authority="": 设置kuebconfig配置文件中集群选项中的certificate-authority路径。
      --embed-certs=false: 设置kuebconfig配置文件中集群选项中的embed-certs开关。
      --insecure-skip-tls-verify=false: 设置kuebconfig配置文件中集群选项中的insecure-skip-tls-verify开关。
      --server="": 设置kuebconfig配置文件中集群选项中的server。

kubectl config set-context
set an environment entry in the kubeconfig profile. If an existing name is specified, incorporating new fields and overwrite the old field.

$ kubectl config set-context NAME [--cluster=cluster_nickname] [--user=user_nickname] [--namespace=namespace]

Examples

# 设置gce环境项中的user字段,不影响其他字段。
$ kubectl config set-context gce --user=cluster-admin

Options

      --cluster="": 设置kuebconfig配置文件中环境选项中的集群。
      --namespace="": 设置kuebconfig配置文件中环境选项中的命名空间。
      --user="": 设置kuebconfig配置文件中环境选项中的用户。

kubectl config set-credentials
provided kubeconfig a user entry in the configuration file. If an existing name is specified, incorporating new fields and overwrite the old field.

Client certificate Set: -client-certificate = certfile -client- key = keyfile
secret token provided: -token = bearer_token
based authentication settings: -username = basic_user -password = basic_password
secret token based authentication and can not be used simultaneously.

$ kubectl config set-credentials NAME [--client-certificate=path/to/certfile] [--client-key=path/to/keyfile] [--token=bearer_token] [--username=basic_user] [--password=basic_password]

Examples

# 仅设置cluster-admin用户项下的client-key字段,不影响其他值
$ kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key

# 为cluster-admin用户项设置基础认证选项
$ kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif

# 为cluster-admin用户项开启证书验证并设置证书文件路径
$ kubectl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true

Options

      --client-certificate="": 设置kuebconfig配置文件中用户选项中的证书文件路径。
      --client-key="": 设置kuebconfig配置文件中用户选项中的证书密钥路径。
      --embed-certs=false: 设置kuebconfig配置文件中用户选项中的embed-certs开关。
      --password="": 设置kuebconfig配置文件中用户选项中的密码。
      --token="": 设置kuebconfig配置文件中用户选项中的令牌。
      --username="": 设置kuebconfig配置文件中用户选项中的用户名。

kubectl config set
disposed in a single configuration file kubeconfig value
PROPERTY_NAME use. "" separated, each represents an attribute name or key map, the key map can not contain. "." The new value to be set PROPERTY_VALUE.

$ kubectl config set PROPERTY_NAME PROPERTY_VALUE  

kubectl config unset
remove a single value kubeconfig profile. PROPERTY_NAME use. "" Separated, each represents an attribute name or key map, the key map can not contain. "."

$ kubectl config unset PROPERTY_NAME

kubectl config use-context
to use in an environment kubeconfig item as the current configuration.

$ kubectl config use-context CONTEXT_NAME

kubectl config view
display kubeconfig provided combined, or a specified profile kubeconfig. The user can use the -output = template -template = TEMPLATE to select the output of the specified value.

$ kubectl config view

Examples

# 显示合并后的kubeconfig设置
$ kubectl config view

# 获取e2e用户的密码
$ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2e" }}{{ index .user.password }}{{end}}{{end}}'

Options

      --flatten[=false]: 将读取的kubeconfig配置文件扁平输出为自包含的结构(对创建可迁移的kubeconfig配置文件有帮助)
      --merge=true: 按照继承关系合并所有的kubeconfig配置文件。
      --minify[=false]: 如果为true,不显示目前环境未使用到的任何信息。
      --no-headers[=false]: 当使用默认输出格式时不打印标题栏。
  -o, --output="": 输出格式,只能使用json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...中的一种。参见golang模板[http://golang.org/pkg/text/template/#pkg-overview]和jsonpath模板[http://releases.k8s.io/release-1.1/docs/user-guide/jsonpath.md]。
      --output-version="": 输出资源使用的API版本(默认使用api-version)。
      --raw[=false]: 显示未经格式化的字节信息。
  -a, --show-all[=false]: 打印输出时,显示所有的资源(默认隐藏状态为terminated的pod)。
      --sort-by="": 如果不为空,对输出的多个结果根据指定字段进行排序。该字段使用jsonpath表达式(如“ObjectMeta.Name”)描述,并且该字段只能为字符串或者整数类型。
      --template="": 当指定了-o=go-template或-o=go-template-file时使用的模板字符串或者模板文件。模板的格式为golang模板[http://golang.org/pkg/text/template/#pkg-overview]。

kubectl create

By file name or console input, create a resource.
Accepts JSON and YAML description file format.

$ kubectl create -f FILENAME

Examples

# 使用pod.json文件创建一个pod
$ kubectl create -f ./pod.json

# 通过控制台输入的JSON创建一个pod
$ cat pod.json | kubectl create -f -

# 创建一个名为my-dep的deployment,运行busybox镜像。
$ kubectl create deployment my-dep --image=busybox

# 创建一个名为my-namespace的namespace
$ kubectl create namespace my-namespace

# 创建Service名为my-cs为的clusterIP
$ kubectl create service clusterip my-cs --tcp=5678:8080

# 创建Service名为my-ns的ExternalName
$ kubectl create service externalname my-ns --external-name bar.com

# 创建一个Service名为my-lbs的LoadBalancer。
$ kubectl create service loadbalancer my-lbs --tcp=5678:8080

# 创建service名为my-ns的新的nodeport。
$ kubectl create service nodeport my-ns --tcp=5678:8080

# 创建一个名为my-service-account的 service account
$ kubectl create serviceaccount my-service-account

Options

  -f, --filename=[]: 用以创建资源的文件名,目录名或者URL。
  -o, --output="": 输出格式,使用“-o name”来输出简短格式(资源类型/资源名)。
      --schema-cache-dir="/tmp/kubectl.schema": 如果不为空,将API schema缓存为指定文件,默认缓存到“/tmp/kubectl.schema”。
      --validate[=true]: 如果为true,在发送到服务端前先使用schema来验证输入。

kubectl delete

By file name, console input, resource name or label selector delete resources. Accepts JSON and YAML description file format.
You can only specify one of the following types of parameters: file name, type, and resource name, resource type and label selector. Note: delete command does not check the version of the resource, if someone update operation while you perform a delete operation, the update he has done will also be deleted along with resources.

$ kubectl delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)])

Examples

# 通过pod.json文件中指定的资源类型和名称删除一个pod
$ kubectl delete -f ./pod.json

# 通过控制台输入的JSON所指定的资源类型和名称删除一个pod
$ cat pod.json | kubectl delete -f -

# 删除所有名为“baz”和“foo”的pod和service
$ kubectl delete pod,service baz foo

# 删除所有带有lable name=myLabel的pod和service
$ kubectl delete pods,services -l name=myLabel

# 删除UID为1234-56-7890-234234-456456的pod
$ kubectl delete pod 1234-56-7890-234234-456456

# 删除所有的pod
$ kubectl delete pods --all

Options

      --all[=false]: 使用[-all]选择所有指定的资源。
      --cascade[=true]: 如果为true,级联删除指定资源所管理的其他资源(例如:被replication controller管理的所有pod)。默认为true。
  -f, --filename=[]: 用以指定待删除资源的文件名,目录名或者URL。
      --grace-period=-1: 安全删除资源前等待的秒数。如果为负值则忽略该选项。
      --ignore-not-found[=false]: 当待删除资源未找到时,也认为删除成功。如果设置了--all选项,则默认为true。
  -o, --output="": 输出格式,使用“-o name”来输出简短格式(资源类型/资源名)。
  -l, --selector="": 用于过滤资源的Label。
      --timeout=0: 删除资源的超时设置,0表示根据待删除资源的大小由系统决定。

kubectl describe

Details of one / output resource specified.
This combination of commands detailed description API, output specifies a set of resources or a plurality of calls.

$ kubectl describe TYPE NAME_PREFIX

First check if there is an exact match TYPE resources and NAME_PREFIX, if not, more information resources all names beginning with NAME_PREFIX will be output.

Support resources include but are not limited to (not sensitive): pods (po), services (svc), replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), resourcequotas (quota) and secrets.

$ kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME)

Examples

# 描述一个node
$ kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal

# 描述一个pod
$ kubectl describe pods/nginx

# 描述pod.json中的资源类型和名称指定的pod
$ kubectl describe -f pod.json

# 描述所有的pod
$ kubectl describe pods

# 描述所有包含label name=myLabel的pod
$ kubectl describe po -l name=myLabel

# 描述所有被replication controller “frontend”管理的pod(rc创建的pod都以rc的名字作为前缀)
$ kubectl describe pods frontend

Options

  -f, --filename=[]: 用来指定待描述资源的文件名,目录名或者URL。
  -l, --selector="": 用于过滤资源的Label。

kubectl edit

Use the default resource editor server editor.
edit command allows you to directly edit using any command-line tool to get the resources. This command opens the editor you defined by KUBE_EDITOR, GIT_EDITOR or EDITOR environment variable, or directly using the "vi". You can edit multiple sources, but all the changes will only be submitted one time. In addition to command-line parameter, the command also accepts a file name, but the straight-specified file must be earlier than the current version of the resource.
The edited file will use the default version of the API output, or explicitly specified by -output-version option. The default output format is YAML, if you need to use JSON format editing, use -o json option.
When the updated resource if an error occurs, it will create a temporary file on disk, recording unsuccessful update. The most common error when updating the resources of other people also update the server's resources. When this happens, you will need to apply the changes you made to the latest version of the resource, or edit the temporary files saved using the latest version of the resource.

kubectl edit (RESOURCE/NAME | -f FILENAME)

Examples

  # 编辑名为“docker-registry”的service
  $ kubectl edit svc/docker-registry

  # 使用一个不同的编辑器
  $ KUBE_EDITOR="nano" kubectl edit svc/docker-registry

  # 编辑名为“docker-registry”的service,使用JSON格式、v1 API版本
  $ kubectl edit svc/docker-registry --output-version=v1 -o json

Options

  -f, --filename=[]: 用来指定待编辑资源的文件名,目录名或者URL。
  -o, --output="yaml": 输出格式,可选yaml或者json中的一种。
      --output-version="": 输出资源使用的API版本(默认使用api-version)。

kubectl exec

Run inside the container.

$ kubectl exec POD [-c CONTAINER] -- COMMAND 
[args...]

Examples

# 默认在pod 123456-7890的第一个容器中运行“date”并获取输出
$ kubectl exec 123456-7890 date

# 在pod 123456-7890的容器ruby-container中运行“date”并获取输出
$ kubectl exec 123456-7890 -c ruby-container date

# 切换到终端模式,将控制台输入发送到pod 123456-7890的ruby-container的“bash”命令,并将其输出到控制台/
# 错误控制台的信息发送回客户端。
$ kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il

Options

  -c, --container="": 容器名。如果未指定,使用pod中的一个容器。
  -p, --pod="": Pod名。
  -i, --stdin[=false]: 将控制台输入发送到容器。
  -t, --tty[=false]: 将标准输入控制台作为容器的控制台输入。

kubectl get

Gets lists one or more resource information.

$ get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]

Examples

# 列出所有运行的Pod信息。
$ kubectl get pods

# 列出Pod以及运行Pod节点信息。
$ kubectl get pods -o wide

# 列出指定NAME的 replication controller信息。
$ kubectl get replicationcontroller web

# 以JSON格式输出一个pod信息。
$ kubectl get -o json pod web-pod-13je7

# 以“pod.yaml”配置文件中指定资源对象和名称输出JSON格式的Pod信息。
$ kubectl get -f pod.yaml -o json

# 返回指定pod的相位值。
$ kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}

# 列出所有replication controllers和service信息。
$ kubectl get rc,services

# 按其资源和名称列出相应信息。
$ kubectl get rc/web service/frontend pods/web-pod-13je7

# 列出所有不同的资源对象。
$ kubectl get all

kubectl label

Update (add, modify, or delete) label (label) on the resource.

  • label must begin with a letter or number, you can use letters, numbers, hyphens, and underscores, up to 63 characters.
  • If --overwrite is true, you can overwrite the existing label, otherwise it will try to cover the label error.
  • If --resource-version is specified, the updated version will use this resource, otherwise it will use the existing resource version.
$ label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]

Examples

给名为foo的Pod添加label unhealthy=true。

kubectl label pods foo unhealthy=true
给名为foo的Pod修改label 为 'status' / value 'unhealthy',且覆盖现有的value。

kubectl label --overwrite pods foo status=unhealthy
给 namespace 中的所有 pod 添加 label

kubectl label pods --all status=unhealthy
仅当resource-version=1时才更新 名为foo的Pod上的label。

kubectl label pods foo status=unhealthy --resource-version=1
删除名为“bar”的label 。(使用“ - ”减号相连)

kubectl label pods foo bar-

kubectl logs

A log output pod container. If the container contains only one pod can be omitted container name.

$ kubectl logs [-f] [-p] POD [-c CONTAINER]

Examples

# 返回仅包含一个容器的pod nginx的日志快照
$ kubectl logs nginx

# 返回pod ruby中已经停止的容器web-1的日志快照
$ kubectl logs -p -c ruby web-1

# 持续输出pod ruby中的容器web-1的日志
$ kubectl logs -f -c ruby web-1

# 仅输出pod nginx中最近的20条日志
$ kubectl logs --tail=20 nginx

# 输出pod nginx中最近一小时内产生的所有日志
$ kubectl logs --since=1h nginx

Options

  -c, --container="": 容器名。
  -f, --follow[=false]: 指定是否持续输出日志。
      --interactive[=true]: 如果为true,当需要时提示用户进行输入。默认为true。
      --limit-bytes=0: 输出日志的最大字节数。默认无限制。
  -p, --previous[=false]: 如果为true,输出pod中曾经运行过,但目前已终止的容器的日志。
      --since=0: 仅返回相对时间范围,如5s、2m或3h,之内的日志。默认返回所有日志。只能同时使用since和since-time中的一种。
      --since-time="": 仅返回指定时间(RFC3339格式)之后的日志。默认返回所有日志。只能同时使用since和since-time中的一种。
      --tail=-1: 要显示的最新的日志条数。默认为-1,显示所有的日志。
      --timestamps[=false]: 在日志中包含时间戳。

kubectl replace

To replace the resource usage profile or stdin.
Support for JSON and YAML format.

$ replace -f FILENAME

Examples

# 使用pod.json中的数据替换pod。
$ kubectl replace -f ./pod.json

# 根据传入的JSON替换pod。
$ cat pod.json | kubectl replace -f -

# 更新镜像版本(tag)到v4
$ kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -

# 强制替换,删除原有资源,然后重新创建资源
$kubectl replace --force -f ./pod.json

kubectl scale

Accommodating expansion or contraction Deployment, ReplicaSet, Replication Controller Pod or the Job Number.
scale can also specify multiple prerequisites, such as: the current number of copies or --resource-version, performed before stretching ratio is set, the system will first verify whether the prerequisites established.

$ scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)

Examples

# 将名为foo中的pod副本数设置为3。
$ kubectl scale --replicas=3 rs/foo

# 将由“foo.yaml”配置文件中指定的资源对象和名称标识的Pod资源副本设为3。
$ kubectl scale --replicas=3 -f foo.yaml

# 如果当前副本数为2,则将其扩展至3。
$ kubectl scale --current-replicas=2 --replicas=3 deployment/mysql

# 设置多个RC中Pod副本数量。
$ kubectl scale --replicas=5 rc/foo rc/bar rc/baz

Guess you like

Origin www.cnblogs.com/aresxin/p/Kubernetes-kubectl.html