Kubernetes之kubectl常用命令使用指南 2 故障排查

                       

这里写图片描述
kubectl是一个用于操作kubernetes集群的命令行接口,通过利用kubectl的各种命令可以实现各种功能,是在使用kubernetes中非常常用的工具。这里我们会通过一些简单的实例来展现其中一些高频命令的使用方法。
更为重要的是这些命令使用的场景以及能够解决什么样的问题。上篇文章我们介绍了创建和删除相关的几条命令,这篇文章我们来看一下出现问题时最常用的另外九条命令。

常用命令

kubectl故障排查相关,本文将会简单介绍一下如下命令

                                                           
项番 命令 说明
No.1 version 显示客户端和服务器侧版本信息
No.2 api-versions 以group/version的格式显示服务器侧所支持的API版本
No.3 explain 显示资源文档信息
No.4 get 取得确认对象信息列表
No.5 describe 取得确认对象的详细信息
No.6 logs 取得pod中容器的log信息
No.7 exec 在容器中执行一条命令
No.8 cp 从容器考出或向容器考入文件
No.9 attach Attach到一个运行中的容器上

事前准备

kubectl version

version命令用于确认客户端和服务器侧的版本信息,不同的版本的情况变化可能很大,所以故障排除时首先也需要确认的是现场环境的版本信息。
从下面可以清楚地看到,本文验证时所使用的版本为1.5.2

[root@ku8-1 tmp]# kubectl versionClient Version: version.Info{
    Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:57:25Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}Server Version: version.Info{
    Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"08e099554f3c31f6e6f07b448ab3ed78d0520507", GitTreeState:"clean", BuildDate:"2017-01-12T04:52:34Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}[root@ku8-1 tmp]#
  
  
  
  • 1
  • 2
  • 3
  • 4

集群构成

一主三从的Kubernetes集群

                                       
项番 类型 Hostname IP
No.1 Master ku8-1 192.168.32.131
No.1 Node ku8-2 192.168.32.132
No.1 Node ku8-3 192.168.32.133
No.1 Node ku8-4 192.168.32.134
[root@ku8-1 tmp]# kubectl get nodesNAME             STATUS    AGE192.168.32.132   Ready     12m192.168.32.133   Ready     11m192.168.32.134   Ready     11m[root@ku8-1 tmp]# 
  
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

kubectl api-versions

使用api-versions命令可以列出当前版本的kubernetes的服务器端所支持的api版本信息。

[root@ku8-1 tmp]# kubectl api-versionsapps/v1beta1authentication.k8s.io/v1beta1authorization.k8s.io/v1beta1autoscaling/v1batch/v1certificates.k8s.io/v1alpha1extensions/v1beta1policy/v1beta1rbac.authorization.k8s.io/v1alpha1storage.k8s.io/v1beta1v1[root@ku8-1 tmp]#
  
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

kubectl explain

使用kubectl explain可以和kubectl help一样进行辅助的功能确认,使用它可以了解各个部分的说明和组成部分。比如如下可以看到对rc的说明,在故障排除时作用并不具有太大作用,到是可以多读读加深一下对各个部分的理解。

[root@ku8-1 ~]# kubectl explain rcDESCRIPTION:ReplicationController represents the configuration of a replication controller.FIELDS:   apiVersion   <string>     APIVersion defines the versioned schema of this representation of an     object. Servers should convert recognized schemas to the latest internal     value, and may reject unrecognized values. More info:     http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#resources   kind <string>     Kind is a string value representing the REST resource this object     represents. Servers may infer this from the endpoint the client submits     requests to. Cannot be updated. In CamelCase. More info:     http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds   metadata <Object>     If the Labels of a ReplicationController are empty, they are defaulted to     be the same as the Pod(s) that the replication controller manages. Standard     object's metadata. More info:     http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata   spec <Object>     Spec defines the specification of the desired behavior of the replication     controller. More info:     http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status   status   <Object>     Status is the most recently observed status of the replication controller.     This data may be out of date by some window of time. Populated by the     system. Read-only. More info:     http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status[root@ku8-1 ~]# 
  
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值