kubernetes命令合集

kubernetes命令合集: kubectl 是 Kubernetes 自带的客户端,可以用它来直接操作 Kubernetes。

使用格式有两种:

kubectl [flags]
kubectl [command]


get
Display one or many resources
显示一个或多个资源

describe
Show details of a specific resource
显示特定资源的详细信息

create
Create a resource by filename or stdin
过filename或stdin创建资源

update
Update a resource by filename or stdin.
通过filename或stdin更新资源。

delete
Delete a resource by filename, stdin, resource and ID, or by resources and label selector.
按文件名,标准输入,资源和ID或资源和标签选择器删除资源。

namespace
SUPERCEDED: Set and view the current Kubernetes namespace
SUPERCEDED:设置并查看当前的Kubernetes命名空间

log
Print the logs for a container in a pod.
在容器中打印容器的日志。

rolling-update
Perform a rolling update of the given ReplicationController.
执行给定ReplicationController的滚动更新。

resize
Set a new size for a Replication Controller.
为Replication Controller设置新大小。

exec
Execute a command in a container.


port-forward
Forward one or more local ports to a pod.
将一个或多个本地端口转发到pod。

proxy
Run a proxy to the Kubernetes API server
运行代理到Kubernetes API服务器

run-container
Run a particular image on the cluster.
在群集上运行特定映像。

stop
Gracefully shut down a resource by id or filename.


expose
Take a replicated application and expose it as Kubernetes Service
获取复制的应用程序并将其公开为Kubernetes Service

label
Update the labels on a resource
标签标记

config
config modifies kubeconfig files


cluster-info
Display cluster info
显示群集信息

api-versions
Print available API versions.


version
Print the client and server version information.
版本信息

help
Help about any command`

> 这里输入引用文本
——————————————————————————————————————————————————————————————————————————————————————
实例:
1、最简单的启动一个pod的方式:
kubectl run mybusybox --image=busybox

2、启动多个pod的方式:
kubectl run mybusybox --image=busybox --replicas=5
 
3、删除创建的pod:
kubectl delete deployments mybusybox
 
4、列出当前所有的pod:
kubectl get pods
 
5、查看pod的状态:
kubectl describe pod [PODNAME]
 
6、查看集群中存在的各个节点:
kubectl get nodes
 
7、创建带有端口映射的pod:
kubectl run mynginx --image=nginx --port=80 --hostport=8000
 
8、创建带有终端的pod:
kubectl run -i --tty busybox --image=busybox

9、删除利用kubeadm启动kubernetes时启动的kube-proxy
kubectl delete daemonset kube-proxy -n kube-system

10、创建pod或srv
kubectl create -f development.yaml

11、检查将要运行的 Pod 的资源状况
kubectl describe pod podName

12、删除 Pod
kubectl delete pod podName

13、pod有多少副本
kubectl get rc

14、扩展 Pod
kubectl scale --replicas=3 rc podName

15、删除
kubectl delete deployment kubernetes-dashboard --namespace=kube-system
kubectl delete svc kubernetes-dashboard --namespace=kube-system
kubectl delete -f kubernetes-dashboard.yaml 

16、进入pod
kubectl exec -ti podName /bin/bash

17、查看集群信息
kubectl cluster-info

18、查看各组件信息
kubectl -s http://localhost:8080 get componentstatuses

19、查看pods所在的运行节点
kubectl get pods -o wide

20、查看pods定义的详细信息
kubectl get pods -o yaml

21、查看Replication Controller信息
kubectl get rc

22、查看service的信息
kubectl get service

23、查看节点信息
kubectl get nodes

24、按selector名来查找pod
kubectl get pod --selector name=redis

25、查看运行的pod的环境变量
kubectl exec pod名 env

26、创建
kubectl create -f 文件名

27、重建
kubectl replace -f 文件名  [--force]

28、删除
kubectl delete -f 文件名
kubectl delete pod pod名
kubectl delete rc rc名
kubectl delete service service名
kubectl delete pod --all



posted @ 2018-09-14 14:19  乔吉拉德  阅读(102)  评论(0)    收藏  举报