容器编排技术 -- Kubernetes kubectl get 命令详解

容器编排技术 -- Kubernetes kubectl get 命令详解

 

kubectl get

获取列出一个或多个资源的信息。

可以使用的资源包括:

  • all
  • certificatesigningrequests (aka 'csr')
  • clusterrolebindings
  • clusterroles
  • clusters (valid only for federation apiservers)
  • componentstatuses (aka 'cs')
  • configmaps (aka 'cm')
  • controllerrevisions
  • cronjobs
  • daemonsets (aka 'ds')
  • deployments (aka 'deploy')
  • endpoints (aka 'ep')
  • events (aka 'ev')
  • horizontalpodautoscalers (aka 'hpa')
  • ingresses (aka 'ing')
  • jobs
  • limitranges (aka 'limits')
  • namespaces (aka 'ns')
  • networkpolicies (aka 'netpol')
  • nodes (aka 'no')
  • persistentvolumeclaims (aka 'pvc')
  • persistentvolumes (aka 'pv')
  • poddisruptionbudgets (aka 'pdb')
  • podpreset
  • pods (aka 'po')
  • podsecuritypolicies (aka 'psp')
  • podtemplates
  • replicasets (aka 'rs')
  • replicationcontrollers (aka 'rc')
  • resourcequotas (aka 'quota')
  • rolebindings
  • roles
  • secrets
  • serviceaccounts (aka 'sa')
  • services (aka 'svc')
  • statefulsets
  • storageclasses
  • thirdpartyresources

语法

$ 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]

示例

列出所有运行的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

Flags

NameShorthandDefaultUsage
all-namespaces falseIf present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.
allow-missing-template-keys trueIf 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.
experimental-use-openapi-print-columns falseIf true, use x-kubernetes-print-column metadata (if present) from openapi schema for displaying a resource.
export falseIf true, use 'export' for the resources. Exported resources are stripped of cluster-specific information.
filenamef[]Filename, directory, or URL to files identifying the resource to get from a server.
ignore-not-found falseTreat "resource not found" as a successful retrieval.
include-extended-apis trueIf true, include definitions of new APIs via calls to the API server. [default true]
label-columnsL[]Accepts a comma separated list of labels that are going to be presented as columns. Names are case-sensitive. You can also use multiple flag options like -L label1 -L label2...
no-headers falseWhen using the default or custom-column output format, don't print headers (default print headers).
outputo 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').
raw  Raw URI to request from the server. Uses the transport specified by the kubeconfig file.
recursiveRfalseProcess the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
schema-cache-dir ~/.kube/schemaIf non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema'
selectorl Selector (label query) to filter on, supports '=', '==', and '!='.
show-allafalseWhen printing, show all resources (default hide terminated pods.)
show-kind falseIf present, list the resource type for the requested object(s).
show-labels falseWhen 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].
watchwfalseAfter listing/getting the requested object, watch for changes.
watch-only falseWatch for changes to the requested object(s), without listing/getting first.
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kubernetes,也称为K8s,是一个开放源代码系统,用于跨多个主机管理容器化的应用程序。 Kubernetes 是用于自动部署,扩展和管理容器化应用程序的开源系统。 它将组成应用程序的容器组合成逻辑单元,以便于管理和服务发现。Kubernetes 源自Google 15 年生产环境的运维经验,同时凝聚了社区的最佳创意和实践。 Kubernetes 是一个开源的容器编排引擎,用来对容器化应用进行自动化部署、 扩缩和管理。该项目托管在 CNCF。 Kubernetes 特性: 自动化上线和回滚 Kubernetes 会分步骤地将针对应用或其配置的更改上线,同时监视应用程序运行状况以确保你不会同时终止所有实例。如果出现问题,Kubernetes 会为你回滚所作更改。你应该充分利用不断成长的部署方案生态系统。 服务发现与负载均衡 无需修改你的应用程序即可使用陌生的服务发现机制。Kubernetes容器提供了自己的 IP 地址和一个 DNS 名称,并且可以在它们之间实现负载均衡。 服务拓扑(Service Topology) 基于集群拓扑的服务流量路由。 存储编排 自动挂载所选存储系统,包括本地存储、诸如 GCP 或 AWS 之类公有云提供商所提供的存储或者诸如 NFS、iSCSI、Gluster、Ceph、Cinder 或 Flocker 这类网络存储系统。 Secret 和配置管理 部署和更新 Secrets 和应用程序的配置而不必重新构建容器镜像,且 不必将软件堆栈配置中的秘密信息暴露出来。 自动装箱 根据资源需求和其他约束自动放置容器,同时避免影响可用性。将关键性工作负载和尽力而为性质的服务工作负载进行混合放置,以提高资源利用率并节省更多资源。 批量执行 除了服务之外,Kubernetes 还可以管理你的批处理和 CI 工作负载,在期望时替换掉失效的容器。 IPv4/IPv6 双协议栈 为 Pod 和 Service 分配 IPv4 和 IPv6 地址 水平扩缩 使用一个简单的命令、一个 UI 或基于 CPU 使用情况自动对应用程序进行扩缩。 自我修复 重新启动失败的容器,在节点死亡时替换并重新调度容器,杀死不响应用户定义的健康检查的容器,并且在它们准备好服务之前不会将它们公布给客户端。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值