Kubectl 操作示例说明
创建资源对象
[root@Docker /] kubectl create -f my-service.yaml -f my-rc.yaml
[root@Docker /] kubectl create -f <directory>
[root@Docker /] kubectl create -f .
[root@Docker /] kubectl apply -f .
它的使用方法与 create 类似,但是这属于更高级的一种方式,在官方说明中它是一种声明式方法。
查看资源对象
#查看索引 Pod 列表:
[root@Docker /] kubectl get pods
#查看 rc 和 service 列表:
[root@Docker /] kubectl get rc,service
描述资源对象
[root@Docker /] kubectl describe nodes <node-name>
[root@Docker /] kubectl describe pods/<pod-name>
[root@Docker /] kubectl describe pods <rc-name>
删除资源对象
[root@Docker /] kubectl delete -f pod.yaml
[root@Docker /] kubect; delete pods,service -l name=<label-name>
[root@Docker /] kubectl delete pods --all
执行容器的命令
#执行 Pod 的 date 命令,默认使用 Pod 中的第一个容器执行:
[root@Docker /] kubectl exec <pod-name> date
#指定 Pod 中某个容器执行 date 命令:
[root@Docker /] kubectl exec <pod-name> -c <container-name> date
#通过 bash 获得 Pod 中某个容器的 TTY,相当于登入容器
[root@Docker /] kubectl exec -it <pod-name> -c <container-name> /bin/bash
查看容器的日志
[root@Docker /] kubectl logs <pod-name>
[root@Docker /] kubectl logs -f <pod-name> -c <container-name>
Proxy 功能
[root@Docker /] kubectl proxy --address='192.168.11.58' --port=8086 --accept-hosts='^*#'
[root@Docker /] kubectl cluster-info
启动服务
[root@Docker /] kubectl run hello-minikube
[root@Docker /] kubectl expose deployment hello-minikube