Kubernetes kubectl 命令表

本文档详述了Kubernetes中的kubectl命令,包括创建、编辑、获取和管理资源对象,如运行容器镜像、暴露服务、更新资源、进行滚动更新、扩缩容等操作,帮助用户更高效地操作Kubernetes集群。
摘要由CSDN通过智能技术生成

Kubernetes kubectl 命令表

Kubernetes 中文社区-文档
Kubernetes 官网文档

k8s设置alias快捷命令

sudo vim ~/.bashrc

alias k='kubectl'
alias kg='kubectl get' #获取资源信息
alias ks='kubectl set' #设置应用资源
alias ke='kubectl edit' #编辑资源
alias kc='kubectl create' #创建资源
alias kd='kubectl delete' #删除
alias krollout='kubectl rollout' #输出、查看、回滚
alias klabel='kubectl label' #更新资源对象的label
alias kpatch='kubectl patch' #更新资源对象字段

1)kubectl-run创建容器镜像

语法:

run NAME --image=image [–env=“key=value”] [–port=port] [–replicas=replicas] [–dry-run=bool] [–overrides=inline-json] [–command] – [COMMAND] [args…]

示例:
启动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

其它详细说明

名称 速记 默认 用法
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.
attach false If true, wait for the Pod to start running, and then attach to the Pod as if ‘kubectl attach …’ were called. Default false, unless ‘-i/–stdin’ is set, in which case the default is true. With ‘–restart=Never’ the exit code of the container process is returned.
command false If true and extra arguments are present, use them as the ‘command’ field in the container, rather than the ‘args’ field which is the default.
dry-run false If true, only print the object that would be sent, without sending it.
env [] Environment variables to set in the container
expose false If true, a public, external service is created for the container(s) which are run
generator The name of the API generator to use, see http://kubernetes.io/docs/user-guide/kubectl-conventions/#generators for a list.
hostport -1 The host port mapping for the container port. To demonstrate a single-machine container.
image The image for the container to run.
image-pull-policy The image pull policy for the container. If left empty, this value will not be specified by the client and defaulted by the server
include-extended-apis true If true, include definitions of new APIs via calls to the API server. [default true]
labels l Labels to apply to the pod(s).
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’. Note that server side components may assign limits depending on the server configuration, such as limit ranges.
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’).
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.
pod-running-timeout 1m0s The length of time (like 5s, 2m, or 3h, higher than zero) to wait until at least one pod is running
port The port that this container exposes. If --expose is true, this is also the port used by the service that is created.
quiet false If true, suppress prompt messages.
record false Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.
replicas r 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, if set to ‘OnFailure’ a job is created, if set to ‘Never’, a regular pod is created. For the latter two --replicas must be 1. Default ‘Always’, for CronJobs Never.
rm false If true, delete resources created i
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值