Kubernetes kubectl 命令表
-
- k8s设置alias快捷命令
- 1)kubectl-run创建容器镜像
- 2)kubectl-expose(将资源暴露为新的Service)
- 3)kubectl-annotate(更新资源的Annotations信息)
- 4)kubectl-autoscale(Pod水平自动伸缩)
- 5)kubectl-convert(转换配置文件为不同的API版本)
- 6)kubectl-create(创建一个集群资源对象
- 7)kubectl-create-clusterrole(创建ClusterRole)
- 8)kubectl-create-clusterrolebinding(为特定的ClusterRole创建ClusterRoleBinding)
- 9)kubectl-create-configmap(创建configmap)
- 10)kubectl-create-deployment(创建deployment)
- 11)kubectl-create-namespace(创建namespace)
- 12)kubectl-create-poddisruptionbudget(创建poddisruptionbudget)
- 13)kubectl-create-quota(创建resourcequota)
- 14)kubectl-create-role(创建role)
- 15)kubectl-create-rolebinding(为特定Role或ClusterRole创建RoleBinding)
- 16)kubectl-create-service(使用指定的子命令创建Service服务)
- 17)kubectl-create-service-clusterip
- 18)kubectl-create-service-externalname
- 19)kubectl-create-service-loadbalancer
- 20)kubectl-create-service-nodeport
- 21)kubectl-create-serviceaccount
- 22)kubectl-create-secret(使用指定的子命令创建secret)
- 23)kubectl-create-secret-tls
- 24)kubectl-create-secret-generic
- 25)kubectl-create-secret-docker-registry
- 26)kubectl-delete(删除资源对象)
- 27)kubectl-edit(编辑服务器上定义的资源对象)
- 28)kubectl-get(获取资源信息)
- 29)kubectl-label(更新资源对象的label)
- 30)kubectl-patch(使用patch更新资源对象字段)
- 31)kubectl-replace(替换资源对象)
- 32)kubectl-rolling-update(使用RC进行滚动更新)
- 33)kubectl-scale(扩缩Pod数量)
- 34)kubectl-rollout(对资源对象进行管理)
- 35)kubectl-rollout-history(查看历史版本)
- 36)kubectl-rollout-pause(标记资源对象为暂停状态)
- 37)kubectl-rollout-resume(恢复已暂停资源)
- 38)kubectl-rollout-status(查看资源状态)
- 39)kubectl-rollout-undo(回滚版本)
- 40)kubectl-set(配置应用资源)
- 41)kubectl-set-resources(指定Pod的计算资源需求)
- 42)kubectl-set-selector(设置资源对象selector)
- 43)kubectl-set-image(更新已有资源对象中的容器镜像)
- 44)kubectl-set-subject(更新RoleBinding/ClusterRoleBinding中User、Group或ServiceAccount)
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 |