linux cpu占用率如何看
425
2022-11-09
kubectl命令管理工具
kubectl命令管理工具
Kubectl是管理k8s集群的命令行工具,通过生成的json格式传递给apiserver进行创建、查看、管理的操作。
//帮助信息 [root@localhost bin]# kubectl --help 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 使用 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 资源. cluster-info 显示集群信息 top Display Resource (CPU/Memory/Storage) usage. cordon 标记 node 为 unschedulable uncordon 标记 node 为 schedulable drain Drain node in preparation for maintenance taint 更新一个或者多个 node 上的 taints 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
项目的生命周期,创建--发布--更新--回滚--删除
//创建 kubectl run命令
kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas]
[--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...] [options]
示例:
[root@localhost bin]# kubectl run nginx-deployment --image=nginx --port=80 --replicas=3
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/nginx-deployment created
[root@localhost bin]# kubectl get pods
]NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-whwhl 1/1 Running 0 2d17h
nginx-deployment-5477945587-b8r6m 1/1 Running 0 70s
nginx-deployment-5477945587-dz8hb 1/1 Running 0 70s
nginx-deployment-5477945587-wd82l 1/1 Running 0 70s
[root@localhost bin]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginx-dbddb74b8-whwhl 1/1 Running 0 2d17h
pod/nginx-deployment-5477945587-b8r6m 1/1 Running 0 3m9s
pod/nginx-deployment-5477945587-dz8hb 1/1 Running 0 3m9s
pod/nginx-deployment-5477945587-wd82l 1/1 Running 0 3m9s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1
发布nginx service提供负载均衡的功能
kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP]
[--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type]
[options]
[root@localhost bin]# kubectl expose deployment nginx --port=80 --target-port=80 --name=nginx-service --type=NodePort
service/nginx-service exposed
[root@localhost bin]# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-7697996758-jbln5 1/1 Running 0 10m
pod/nginx-7697996758-xgxzd 1/1 Running 0 10m
pod/nginx-7697996758-xjdlz 1/1 Running 0 10m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1
在node01操作,查看负载均衡端口38804kubernetes里kube-proxy支持三种模式,在v1.8之前我们使用的是iptables 以及 userspace两种模式,在kubernetes 1.8之后引入了ipvs模式
[root@localhost ~]# yum install ipvsadm -y [root@localhost ~]# ipvsadm -L -n TCP 192.168.195.150:38804 rr -> 172.17.27.3:80 Masq 1 0 0 -> 172.17.31.3:80 Masq 1 0 0 -> 172.17.31.4:80 Masq 1 0 0 //在node02操作 同样安装ipvsadmin工具查看 [root@localhost ~]# ipvsadm -L -n TCP 192.168.195.151:38804 rr -> 172.17.27.3:80 Masq 1 0 0 -> 172.17.31.3:80 Masq 1 0 0 -> 172.17.31.4:80 Masq 1 0 0 //在master01操作 查看访问日志(注意:如果访问其他node无法访问检查proxy组件) [root@localhost bin]# kubectl get pods ]NAME READY STATUS RESTARTS AGE nginx-7697996758-jbln5 1/1 Running 0 30m nginx-7697996758-xgxzd 1/1 Running 0 30m nginx-7697996758-xjdlz 1/1 Running 0 30m [root@localhost bin]# kubectl logs nginx-7697996758-jbln5 172.17.27.1 - - [10/Feb/2020:04:51:56 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" "-" 2020/02/10 04:51:56 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.27.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.195.151:38804", referrer: "http://192.168.195.151:38804/" 172.17.27.1 - - [10/Feb/2020:04:51:56 +0000] "GET /favicon.ico HTTP/1.1" 404 555 ""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" "-" [root@localhost bin]# kubectl logs nginx-7697996758-xgxzd [root@localhost bin]# kubectl logs nginx-7697996758-xjdlz 172.17.31.1 - - [10/Feb/2020:04:51:43 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" "-" 2020/02/10 04:51:44 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.31.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.195.150:38804", referrer: "http://192.168.195.150:38804/" 172.17.31.1 - - [10/Feb/2020:04:51:44 +0000] "GET /favicon.ico HTTP/1.1" 404 555 ""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36" "-"
[root@localhost bin]# kubectl set --help
]Configure application resources
These commands help you make changes to existing application resources.
Available Commands:
env Update environment variables on a pod template
image 更新一个 pod template 的镜像
resources 在对象的 pod templates 上更新资源的 requests/limits
selector 设置 resource 的 selector
serviceaccount Update ServiceAccount of a resource
subject Update User, Group or ServiceAccount in a
RoleBinding/ClusterRoleBinding
Usage:
kubectl set SUBCOMMAND [options]
Use "kubectl
[root@localhost bin]# kubectl rollout --help
Manage the rollout of a resource.
Valid resource types include:
* deployments
* daemonsets
* statefulsets
Examples:
# Rollback to the previous deployment
kubectl rollout undo deployment/abc
# Check the rollout status of a daemonset
kubectl rollout status daemonset/foo
Available Commands:
history 显示 rollout 历史
pause 标记提供的 resource 为中止状态
resume 继续一个停止的 resource
status 显示 rollout 的状态
undo 撤销上一次的 rollout
Usage:
kubectl rollout SUBCOMMAND [options]
Use "kubectl
//删除nginx
//查看deployment
[root@localhost bin]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx 3 3 3 3 118m
[root@localhost bin]# kubectl delete deployment/nginx
deployment.extensions "nginx" deleted
[root@localhost bin]# kubectl get deploy
No resources found.
[root@localhost bin]# kubectl get pods
No resources found.
//删除服务SVC
[root@localhost bin]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~