k8s kubectl run命令使用详解
生活随笔
收集整理的這篇文章主要介紹了
k8s kubectl run命令使用详解
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
k8s kubectl run命令使用詳解
在集群上運(yùn)行指定鏡像。
摘要
創(chuàng)建并運(yùn)行一個(gè)指定的可復(fù)制的鏡像。 創(chuàng)建一個(gè)deployment或者job來管理創(chuàng)建的容器。
kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]示例
# 啟動(dòng)一個(gè) Nginx 實(shí)例。 kubectl run nginx --image=nginx# 啟動(dòng)一個(gè) hazelcast 單個(gè)實(shí)例,并開放容器的5701端口。 kubectl run hazelcast --image=hazelcast --port=5701# 運(yùn)行一個(gè) hazelcast 單個(gè)實(shí)例,并設(shè)置容器的環(huán)境變量"DNS_DOMAIN=cluster" and "POD_NAMESPACE=default"。 kubectl run hazelcast --image=hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"# 啟動(dòng)一個(gè) replicated 實(shí)例去復(fù)制 nginx。 kubectl run nginx --image=nginx --replicas=5# 試運(yùn)行。不創(chuàng)建他們的情況下,打印出所有相關(guān)的 API 對(duì)象。 kubectl run nginx --image=nginx --dry-run# 用可解析的 JSON 來覆蓋加載 `deployment` 的 `spec`,來運(yùn)行一個(gè) nginx 單個(gè)實(shí)例。 kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'# 運(yùn)行一個(gè)在前臺(tái)運(yùn)行的 busybox 單個(gè)實(shí)例,如果退出不會(huì)重啟。 kubectl run -i --tty busybox --image=busybox --restart=Never# 使用默認(rèn)命令來啟動(dòng) nginx 容器,并且傳遞自定義參數(shù)(arg1 .. argN)給 nginx。 kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN># 使用不同命令或者自定義參數(shù)來啟動(dòng) nginx 容器。 kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN># 啟動(dòng) perl 容器來計(jì)算 bpi(2000) 并打印出結(jié)果。 kubectl run pi --image=perl --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(2000)'選項(xiàng)
--attach[=false]: 如果為true, 那么等 pod 開始運(yùn)行之后,鏈接到這個(gè) pod 和運(yùn)行 'kubectl attach ...'一樣。默認(rèn)是 false,除非設(shè)置了 '-i/--interactive' 默認(rèn)才會(huì)是 true。--command[=false]: 如果為 true 并且有其他參數(shù),那么在容器中運(yùn)行這個(gè)'command',而不是默認(rèn)的'args'。--dry-run[=false]: 如果為 true,則僅僅打印這個(gè)對(duì)象,而不會(huì)執(zhí)行命令。--env=[]: 設(shè)置容器的環(huán)境變量。--expose[=false]: 如果為 true, 會(huì)為這個(gè)運(yùn)行的容器創(chuàng)建一個(gè)公開的 service。--generator="": The name of the API generator to use. Default is 'deployment/v1beta1' if --restart=Always, otherwise the default is 'job/v1'. This will happen only for cluster version at least 1.2, for olders we will fallback to 'run/v1' for --restart=Always, 'run-pod/v1' for others.--hostport=-1: The host port mapping for the container port. To demonstrate a single-machine container.--image="": 用來運(yùn)行的容器鏡像。--include-extended-apis[=true]: If true, include definitions of new APIs via calls to the API server. [default true]-l, --labels="": pod 的標(biāo)簽。--leave-stdin-open[=false]: If the pod is started in interactive mode or with stdin, leave stdin open after the first attach completes. By default, stdin will be closed after the first attach completes.--limits="": The resource requirement limits for this container. For example, 'cpu=200m,memory=512Mi'--no-headers[=false]: 當(dāng)使用默認(rèn)輸出格式時(shí)不打印標(biāo)題欄。-o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/release-1.2/docs/user-guide/jsonpath.md].--output-version="": Output the formatted object with the given group version (for ex: 'extensions/v1beta1').--overrides="": An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field.--port=-1: The port that this container exposes. If --expose is true, this is also the port used by the service that is created.--record[=false]: Record current kubectl command in the resource annotation.-r, --replicas=1: Number of replicas to create for this container. Default is 1.--requests="": The resource requirement requests for this container. For example, 'cpu=100m,memory=256Mi'. Note that server side components may assign requests depending on the server configuration, such as limit ranges.--restart="Always": The restart policy for this Pod. Legal values [Always, OnFailure, Never]. If set to 'Always' a deployment is created for this pod, if set to 'OnFailure', a job is created for this pod, if set to 'Never', a regular pod is created. For the latter two --replicas must be 1. Default 'Always'--rm[=false]: If true, delete resources created in this command for attached containers.--save-config[=false]: If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future.--service-generator="service/v2": The name of the generator to use for creating a service. Only used if --expose is true--service-overrides="": An inline JSON override for the generated service object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field. Only used if --expose is true.-a, --show-all[=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.-i, --stdin[=false]: Keep stdin open on the container(s) in the pod, even if nothing is attached.--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].-t, --tty[=false]: Allocated a TTY for each container in the pod.繼承自父命令的選項(xiàng)
--alsologtostderr[=false]: 同時(shí)輸出日志到標(biāo)準(zhǔn)錯(cuò)誤控制臺(tái)和文件。--certificate-authority="": 用以進(jìn)行認(rèn)證授權(quán)的.cert文件路徑。--client-certificate="": TLS使用的客戶端證書路徑。--client-key="": TLS使用的客戶端密鑰路徑。--cluster="": 指定使用的kubeconfig配置文件中的集群名。--context="": 指定使用的kubeconfig配置文件中的環(huán)境名。--insecure-skip-tls-verify[=false]: 如果為true,將不會(huì)檢查服務(wù)器憑證的有效性,這會(huì)導(dǎo)致你的HTTPS鏈接變得不安全。--kubeconfig="": 命令行請(qǐng)求使用的配置文件路徑。--log-backtrace-at=:0: 當(dāng)日志長(zhǎng)度超過定義的行數(shù)時(shí),忽略堆棧信息。--log-dir="": 如果不為空,將日志文件寫入此目錄。--log-flush-frequency=5s: 刷新日志的最大時(shí)間間隔。--logtostderr[=true]: 輸出日志到標(biāo)準(zhǔn)錯(cuò)誤控制臺(tái),不輸出到文件。--match-server-version[=false]: 要求服務(wù)端和客戶端版本匹配。--namespace="": 如果不為空,命令將使用此namespace。--password="": API Server進(jìn)行簡(jiǎn)單認(rèn)證使用的密碼。-s, --server="": Kubernetes API Server的地址和端口號(hào)。--stderrthreshold=2: 高于此級(jí)別的日志將被輸出到錯(cuò)誤控制臺(tái)。--token="": 認(rèn)證到API Server使用的令牌。--user="": 指定使用的kubeconfig配置文件中的用戶名。--username="": API Server進(jìn)行簡(jiǎn)單認(rèn)證使用的用戶名。--v=0: 指定輸出日志的級(jí)別。--vmodule=: 指定輸出日志的模塊,格式如下:pattern=N,使用逗號(hào)分隔。參考鏈接
- http://kubernetes.kansea.com/docs/user-guide/kubectl/kubectl_run/
- http://docs.kubernetes.org.cn/468.html
總結(jié)
以上是生活随笔為你收集整理的k8s kubectl run命令使用详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: helm部署kafka完整记录
- 下一篇: k8s kubectl create命令