'//Kubectl是管理K8S集群的命令行工具''//通过生成的json格式传递给apiserver进行创建、查看、管理的操作''//帮助信息'[root@master01 ~]# kubectl --help
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
'//K8S官网关于Kubectl的概述'
Basic Commands (Beginner):
create Create a resource from a file or from stdin.
'//从文件(json、yaml)或标准输入(命令)中创建资源'
expose 使用 replication controller, service, deployment 或者 pod 并暴露它作为一个新的 Kubernetes Service
run 在集群中运行一个指定的镜像
set 为 objects(具体的对象)设置一个指定的特征
Basic Commands (Intermediate):
explain 查看资源的文档
get 显示一个或更多 resources(资源)
edit 在服务器上编辑一个资源
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 为 Deployment, ReplicaSet, Replication Controller 或者 Job 设置一个新的副本数量(保持)
autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量
Cluster Management Commands: '//集群管理命令'
certificate 修改 certificate 资源.(例如master同意node申请,颁发证书)
cluster-info 显示集群信息
top Display Resource (CPU/Memory/Storage) usage.
'//检查集群中资源占用'
cordon 标记 node 为 unschedulable
'//设置标记,可以确定该节点是否被分配pod资源'
uncordon 标记 node 为 schedulable
drain Drain node in preparation for maintenance
'//从集群中移除节点'
taint 更新一个或者多个 node 上的 taints
'//污点,使节点排斥一类特定的pod,避免pod被分配至不合适的节点上'
Troubleshooting and Debugging Commands: '//故障排查和调试命令'
describe 显示一个指定 resource 或者 group 的 resources 详情
'//检查详细信息,排障时经常用到'
logs 输出容器在 pod 中的日志
attach Attach 到一个运行中的 container
exec 在一个 container 中执行一个命令
port-forward Forward one or more local ports to a pod
proxy 运行一个 proxy 到 Kubernetes API server
cp 复制 files 和 directories 到 containers 和从容器中复制 files 和 directories.
auth Inspect authorization
Advanced Commands:
apply 通过文件名或标准输入流(stdin)对资源进行配置(带更新内容)
patch 使用 strategic merge patch 更新一个资源的 field(s)
replace 通过 filename 或者 stdin替换一个资源
wait Experimental: Wait for a specific condition on one or many resources.
convert 在不同的 API versions 转换配置文件
Settings Commands:
label 更新在这个资源上的 labels(打标签)
annotate 更新一个资源的注解
completion Output shell completion code for the specified shell (bash or zsh)
Other Commands:
alpha Commands for features in alpha
api-resources Print the supported API resources on the server
'//打印输出服务器上支持的API资源(缩写)'
api-versions Print the supported API versions on the server, in the form of "group/version"'//以过滤出版本的形式打印输出API资源,v1版本,v1veta1测试'
config 修改 kubeconfig 文件
plugin Provides utilities for interacting with plugins.
version 输出 client 和 server 的版本信息
Usage:
kubectl [flags][options]
Use "kubectl <command> --help"formore information about a given command.
Use "kubectl options"for a list of global command-line options (applies to all commands).
2.一个项目完整的生命周期
①删除
'//一个项目完整的生命周期:创建--》发布--》更新--》回滚--》删除'
---
[root@master01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-m5mvj 1/1 Running 0 3d21h
[root@master01 ~]# kubectl delete pod nginx-dbddb74b8-m5mvj
pod "nginx-dbddb74b8-m5mvj" deleted
[root@master01 ~]# kubectl get pod '//可以发现,pod会再生'
NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-8vnw7 0/1 ContainerCreating 0 7s
[root@master01 ~]