查看版本
kubectl version
查看节点
kubectl get nodes
部署app
说明: 提供deployment名称和app镜像地址(docker镜像地址)
kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080
再如:
run test --image=preparedman/mytomcat:tagname --port=8088
查看app
kubectl proxy
测试:curl http://localhost:8001/version
{"major": "1","minor": "13","gitVersion": "v1.13.3","gitCommit": "721bfa751924da8d1680787490c54b9179b1fed0","gitTreeState": "clean","buildDate": "2019-02-01T20:00:57Z","goVersion": "go1.11.5","compiler": "gc","platform": "linux/amd64"}
获取pod名字
export POD_NAME=$(kubectl get pods -o go-template --template '{ {range .items}}{ {.metadata.name}}{ {"\n"}}{ {end}}')
测试:echo Name of the Pod: $POD_NAME
使用kubectl进行故障排除
主要使用如下命令
kubectl get -list resources 列出资源
kubectl describe-show detailed information about a resource 显示资源详情
kubectl logs- print the logs from a container ina pod 打印`pod` 中container的日志
kubectl exec- execute a command on a container in a pod 在`pod`中的container上执行命令
获取应用配置
查看应用是否在运行
kubectl get pods
查看pod 中有哪些container
kubectl describe pods
结果如下:
Name: kubernetes-bootcamp-6bf84cb898-jk4jc
Namespace: default
Priority:0PriorityClassName:Node: minikube/172.17.0.72Start Time: Wed,24 Apr 2019 13:21:58 +0000Labels: pod-template-hash=6bf84cb898
run=kubernetes-bootcamp
Annotations:Status: Running
IP:172.18.0.4Controlled By: ReplicaSet/kubernetes-bootcamp-6bf84cb898
Containers:
kubernetes-bootcamp:
Container ID: docker://55491b363d26b62e432cd4841ed4f65cc5b98e645d172c6ed88feaebcb4ec06c
Image: gcr.io/google-