Kubernetes--kubectl
一、Kubectl命令行说明
| 类型 | 命令 | 描述 |
| 基础命令 | create | 通过文件名或标准输入创建资源 |
| expose | 将一个资源公开为一个新的kubernetes服务 | |
| run |
创建并运行一个特定的镜像,可能是副本 创建一个deployment或job管理创建的容器 |
|
| set |
配置应用资源 修改现有应用程序资源 |
|
| get | 显示一个或多个资源 | |
| explain | 文档参考资料 | |
| edit | 使用默认的编辑器编辑一个资源 | |
| delete | 通过文件名、标准输入、资源名称或标签选择器来删除资源 | |
| 部署命令 | rollout | 管理资源的发布 |
| rolling-update | 执行指定复制控制器的滚动更新 | |
| scale | 扩容或缩容Pod数量,Deployment、ReplicasSet、RC或Job | |
| autoscale | 创建一个自动选择扩容或者缩容并设置Pod数量 | |
| 集群管理命令 | certificate | 修改证书资源 |
| cluster-info | 显示集群信息 | |
| top | 显示资源(CPUMemory/Storage) | |
| cordon | 标记节点为不可调度 | |
| uncordon | 标记节点可调度 | |
| drain | 维护期间排除节点 | |
| taint | 更新一个或多个节点上的污点 | |
| 排错/调试 | describe | 显示特定资源或资源组的详细信息 |
| logs | 打印pod中容器的日志 | |
| attach | 连接到一个运行的容器,既可以查看output stream,也可以与容器(stdin)进行交互 | |
| exec | 在容器中执行命令 | |
| port-forward | 将一个或多个本地端口转发到pod中 | |
| proxy | 运行Kubernetes API服务器的代理 | |
| cp | 从容器中复制文件或目录 | |
| auth | 检查授权 | |
| 高级命令 | apply | 通过文件名或标准输入将配置应用于资源 |
| patch | 使用(patch)补丁修改、更新资源的字段 | |
| replace | 用文件名或标准输入替换资源 | |
| convert | 在不同的API版本之间转换配置文件 | |
| 设置命令 | label | 更新资源的标签 |
| annotate | 更新资源上的注释 | |
| completion | 输出指定shell的代码(bash or zsh) | |
| 其他命令 | api-versions | 在服务器上打印支持的API版本,格式为“group / version” |
| config | 修改Kubernetes的文件 | |
| help | help命令 | |
| plugin | 显示安装的插件 | |
| version | 显示版本信息 |
具体可以参考:https://kubernetes.io/docs/reference/kubectl/kubectl/
二、kubectl事例
(1)创建一个deployment(deployment用来管理Pod和RS)
# kubectl run hello-world --replicas=3 --labels="app=example_nginx" --image=nginx:1.10 --port=80
deployment.apps "hello-world" created # 备注
hello-world : deployment的名称 --replicas:副本数 --labels:标签(非唯一,用于识别用途等特点) --image:使用的镜像 --port:暴露的端口
(2)查看pod
[root@master-01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-world-76c54b84b-b5bcz 1/1 Running 0 11m
hello-world-76c54b84b-bmhsd 1/1 Running 0 11m
hello-world-76c54b84b-rgn2q 1/1 Running 0 11m
[root@master-01 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-world-76c54b84b-b5bcz 1/1 Running 0 11m 10.20.184.81 master-01
hello-world-76c54b84b-bmhsd 1/1 Running 0 11m 10.20.254.104 node-03
hello-world-76c54b84b-rgn2q 1/1 Running 0 11m 10.20.190.57 node-01
(3)查看deployment
[root@master-01 ~]# kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-world 3 3 3 3 12
(4)查看pod的描述信息
[root@master-01 ~]# kubectl describe pod hello-world-76c54b84b-b5bcz
Name: hello-world-76c54b84b-b5bcz
Namespace: default
Node: master-01/172.16.60.95
Start Time: Wed, 20 Jun 2018 09:53:07 +0800
Labels: app=example_nginx
pod-template-hash=327106406
Annotations: <none>
Status: Running
IP: 10.20.184.81
Controlled By: ReplicaSet/hello-world-76c54b84
.
.
.
(5)描述deployment信息
[root@master- ~]# kubectl describe deploy/hello-world
Name: hello-world
Namespace: default
CreationTimestamp: Wed, Jun :: +
Labels: app=example_nginx
Annotations: deployment.kubernetes.io/revision=
Selector: app=example_nginx
Replicas: desired | updated | total | available | unavailable
StrategyType: RollingUpdate
MinReadySeconds:
RollingUpdateStrategy: max unavailable, max surge
Pod Template:
Labels: app=example_nginx
Containers:
hello-world:
Image: nginx:1.10
Port: /TCP
Host Port: /TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: hello-world-76c54b84b (/ replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 18m deployment-controller Scaled up replica set hello-world-76c54b84b to
(6)查看其它命名空间的资源(--namespace xxx / -n xxx)
[root@master-01 ~]# kubectl get pod -o wide -n kube-system
NAME READY STATUS RESTARTS AGE IP NODE
calico-kube-controllers-98989846-gjk55 1/1 Running 1 8d 172.16.60.98 node-02
calico-node-4mxvv 1/1 Running 1 8d 172.16.60.98 node-02
calico-node-ftg9v 1/1 Running 1 8d 172.16.60.96 master-02
calico-node-hctvm 1/1 Running 1 8d 172.16.60.97 node-01
calico-node-rbv5b 1/1 Running 1 8d 172.16.60.99 node-0
(7)edit修改配置
# 将刚才port的80 改为8088 [root@master-01 ~]# kubectl edit deploy hello-world ...
...
...
ports:
- containerPort: 8088
...
...
describe检查
[root@master-01 ~]# kubectl describe deploy/hello-world
...
...
...
Pod Template:
Labels: app=example_nginx
Containers:
hello-world:
Image: nginx:1.10
Port: 8088/TCP
Host Port: 0/TCP
(8)创建一个Service对象,暴露Deployment端口
[root@master-01 ~]# kubectl expose deploy/hello-world --port=88 --type=NodePort --target-port=80 --name=example-nginx-service
service "example-nginx-service" exposed # 备注
--port=88:Service服务的端口 --target-port=80: 容器暴露的端口 --type=NodePort:会随机开放一个宿主机端口(端口范围在apiserver中定义)
查看/描述 服务
[root@master-01 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
example-nginx-service NodePort 10.254.43.65 <none> 88:40591/TCP 5m [root@master-01 ~]# kubectl describe svc example-nginx-service
Name: example-nginx-service
Namespace: default
Labels: app=example_nginx
Annotations: <none>
Selector: app=example_nginx
Type: NodePort
IP: 10.254.43.65
Port: <unset> 88/TCP
TargetPort: 80/TCP
NodePort: <unset> 40591/TCP
Endpoints: 10.20.184.82:80,10.20.190.59:80,10.20.254.106:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
访问nginx
# 可以通过Service 的cluster-ip:88 / ndoe-ip:40591 [root@master-01 ~]# curl 10.254.43.65:88
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>
# 任意node-ip
[root@master-01 ~]# curl 172.16.60.95:40591
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>
(9)创建一个Service对象,暴露UDP端口
# kubectl expose deploy/hello-world --port=4123 --type=NodePort --protocol=udp --target-port=80 --name=example-upd-service
(10)查看Pod日志
[root@master-01 ~]# kubectl logs pods/hello-world-76c54b84b-rx4vz 172.16.60.95 - - [20/Jun/2018:02:35:20 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
172.16.60.95 - - [20/Jun/2018:02:36:06 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
172.16.60.95 - - [20/Jun/2018:02:36:43 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36" "-"
(11)使用标签查询Pod
[root@master-01 ~]# kubectl get pod --selector="app=example_nginx" -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-world-76c54b84b-8zn5j 1/1 Running 0 18m 10.20.190.59 node-01
hello-world-76c54b84b-pbp9h 1/1 Running 0 18m 10.20.254.106 node-03
hello-world-76c54b84b-rx4vz 1/1 Running 0 18m 10.20.184.82 master-01
Kubernetes--kubectl的更多相关文章
- Kubernetes kubectl 命令
kubectl 命令用来操作 Kubernetes 集群中的资源对象,包括对资源的创建.删除.查看.修改.配置.运行等 命令语法:kubectl [command] [TYPE] [NAME] [fl ...
- [Kubernetes]kubectl命令补全出错
在kubernetes集群中,命令补全能够省很多事,但是这两天就很奇怪 kubectl get pod -n kube+tab键自动补全Namespace的时候出现错误 kubectl get pod ...
- Kubernetes kubectl 命令概述
kubectl用于运行Kubernetes集群命令的管理工具. 语法 kubectl [command] [TYPE] [NAME] [flags] command:指定要在一个或多个资源执行的操作 ...
- Kubernetes,kubectl常用命令详解
kubectl概述 祭出一张图,转载至 kubernetes-handbook/kubectl命令概述 ,可以对命令族有个整体的概念. 环境准备 允许master节点部署pod,使用命令如下: kub ...
- Kubernetes - kubectl proxy
最近在玩flink部署在k8s上,但是k8s以前没玩过,参照前几天写的文章可部署一个简单的k8shttps://www.cnblogs.com/felixzh/p/9726244.html 在参照fl ...
- [Kubernetes] Kubectl and Pod
1. Create and run a Pod kubectl run my-nginx --image=nginx:alpine We can run kubectl get all to see ...
- kubernetes kubectl 命令自动补全
yum install -y bash-completion source /usr/share/bash-completion/bash_completion source <(kubectl ...
- Kubernetes源码之旅:从kubectl到API Server
概述: Kubernetes项目目前依然延续着之前爆炸式的扩张.急需能够理解Kubernetes原理并且贡献代码的软件开发者.学习Kubernetes源码并不容易.Kubernetes是使用相对年轻的 ...
- kubernetes入门(08)kubernetes单机版的安装和使用
kubectl get - 类似于 docker ps ,查询资源列表 kubectl describe - 类似于 docker inspect ,获取资源的详细信息 kubectl logs - ...
- yum方式安装kubernetes
环境准备 master01 node01 node02,连通网络,修改hosts文件,确认3台主机相互解析 vim /etc/hosts 127.0.0.1 localhost localhost.l ...
随机推荐
- 华策光通信: LED可见光通信室内定位项目获最具投资价值奖
3月21日上午,一场持续3个多小时的O2O领域的创业DemoShow在深圳科兴科学园会议中心激烈上演.来自华策光通信的基于LED可见光通信室内精准定位项目作为LED与室内定位领域的跨界融合项目经过精彩 ...
- “Hello World!”团队第六周第六次会议
“Hello World!”团队第六周第六次会议 博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.checkout& ...
- 记事本App之NABCD
在经过了漫长的讨论之后,在经历了无数次提议.否定.再提议.改进之后.我们团队的团队项目终于有了结果,小组成员一致同意做一个移动端记事本的app.下面我就来详细的阐明我们项目的NABCD这5大项内容. ...
- 解决Cygwin编译cocos2dx 遇到的 error: 'UINT64_C' was not declared in this scope 问题
环境工具:Win10.VS2013.cocos2d-x-2.2.6.Cygwin.ADT 问题来源:写了一个小游戏,VS2013上运行成功,就尝试着打包apk,项目导入到ADT里面,添加了cocos2 ...
- lr几个常用的函数
将字符串保存为参数 lr_save_string("string you want to save", "arg_name"); 将int型数字保存为参数 lr ...
- 佣金维护测试sql
SELECT bmc.memberid , case then decode(bmc.source, , , 'TOPfitIBL') ELSE decode(bmc.source, , , 'TOP ...
- Excel作为数据源TesTNG做数据驱动完整代码
说明:EXCEL 支持xls 和xlsx 俩种格式 : 已经过测试 ! package main.java; import org.apache.poi.ss.usermodel.*; import ...
- chrome浏览器下的xdebug helper使用方法
chrome浏览器下的xdebug helper使用方法 自从安装了xdebug后,发现每次调试都需要从eclipse中先从头启动,然后一步步走到你要调试的页面,而不是说想什么时候调试就什么时 ...
- [转帖]ssd固态硬盘的Trim命令是什么?
ssd固态硬盘的Trim命令是什么? 收藏 分享 邀请 许多用户朋友在购买SSD的时候都会特别强调Trim,不过Trim是什么?做什么用的? 什么是Trim? Trim指令也叫disable ...
- [转帖] sqlserver CAL 授权模式下 只能够有20个core的使用问题
http://www.cnblogs.com/diabloxl/p/3623640.html?utm_source=tuicool&utm_medium=referral 公司这边性能组老师进 ...