在基于正式的部署pods对象和services应用的基础上,我们必须保证k8s的环境的搭建的正确性。如下首先我们使用kubectl 检测环境部署的成功与否。出现以下的现象则说明环境搭建成功(本次的项目使用的是一个master和两个nodes节点)。
[root@server1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
server1 Ready master 9m v1.11.1
server2 Ready <none> 5m v1.11.1
server3 Ready <none> 21s v1.11.1
那么kubectl 可以用来交互k8s内部的部署,是API SERVER 交互的工具
那么kubectl本身是不具备自动补齐的,我们为了方便让我们的kubectl自动补齐。
执行以下的步骤就可以了:
[root@server1 ~]# yum -y install bash-completion
[root@server1 ~]# chmod +x /usr/share/bash-completion/bash_completion
[root@server1 ~]# source /usr/share/bash-completion/bash_completion
[root@server1 ~]# source <(kubectl completion bash)
每次开机的时候自动的将命令补齐到自动加载中
[root@server1 ~]# echo "source <(kubectl completion bash)" >> /etc/bashrc
我们使用命令 kubectl tab 两下就可以了
[root@server1 ~]# kubectl
alpha autoscale cp explain plugin set
annotate certificate create expose port-forward taint
api-resources cluster-info delete get proxy top
api-versions completion describe label replace uncordon
apply config drain logs rollout version
attach convert edit options run wait
auth cordon exec patch scale
[root@server1 ~]# kubectl 以下是kubectl的全部的命令的工具
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner): 基础命令
create Create a resource from a file or from stdin.
expose Take a replication controller, service, deployment or pod and expose it as a new
Kubernetes Service
run Run a particular image on the cluster
set Set specific features on objects
Basic Commands (Intermediate): 中级的基础命令
explain Documentation of resources
get Display one or many resources
edit 编辑(改) Edit a resource on the server
delete 删除 Delete resources by filenames, stdin, resources and names, or by resources and
label selector
Deploy Commands:
rollout 滚动 Manage the rollout of a resource
scale 改变应用程序的规模,扩容或者缩容(手动改变) Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job
autoscale 自动改变应用程序的规模 Auto-scale a Deployment, ReplicaSet, or ReplicationController
Cluster Management Commands: 集群管理的相关的工具命令
certificate 证书 Modify certificate resources.
cluster-info 集群信息 Display cluster info
top 硬件的信息 Display Resource (CPU/Memory/Storage) usage.
cordon 标记一个节点不可被调用 Mark node as unschedulable
uncordon 标记一个节点可被调用 Mark node as schedulable
drain Drain node in preparation for maintenance
taint 给节点增加污点,(人生的污点)高级调度相关 Update the taints on one or more nodes
Troubleshooting and Debugging Commands:
describe 描述资源的详细的信息 Show details of a specific resource or group of resources
在这看一个describe的例子,比如看其中的某个节点的详细的信息
[root@server1 ~]# kubectl describe node server2
Name: server2
Roles: <none>
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/hostname=server2
Annotations: flannel.alpha.coreos.com/backend-data={"VtepMAC":"de:82:db:91:7a:bf"}
flannel.alpha.coreos.com/backend-type=vxlan
flannel.alpha.coreos.com/kube-subnet-manager=true
flannel.alpha.coreos.com/public-ip=172.25.254.2
.......
Addresses:
InternalIP: 172.25.254.2
Hostname: server2
Capacity:
cpu: 1
ephemeral-storage: 7254Mi
hugepages-2Mi: 0
memory: 1016504Ki
pods: 110
Allocatable:
cpu: 1
ephemeral-storage: 6845733263
hugepages-2Mi: 0
memory: 914104Ki
pods: 110
........
logs 日志(同docker) Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward 端口转发 Forward on