export KUBECONFIG=~/.kube/config.aws
- 指定namespace
kubectl -n <namespace>
# 获取所有命名空间下的 pod
kubectl get pod -A
# 获取指定命名空间下所有的资源
kubectl -n elk get all
- 获取 node
kubectl get nodes -o wide 获取更多详情
kubectl get nodes -o json json 格式
-o wide
获取更多详情
kubectl get nodes --watch
--watch
一直监听变化
- 获取所有的api资源
kubectl api-resources
常用资源:
nodes
|no
pods
|po
services
|svc
namespaces
|ns
configmaps
|cm
deployments
|deploy
- 列举所有 PV 持久卷,按容量排序
kubectl get pv --sort-by=.spec.capacity.storage
- 获取资源的描述
kubectl explain <资源名>
- 获取 endpoints,service关联的pod的ip地址和端口
kubectl get endpoints
- 创建资源
mysql.yaml
apiVersion: v1
kind: Pod
metadata:
name: mysql
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123123"
kubectl create -f mysql.yaml
kubectl apply -f mysql.yaml
- 删除资源
kubectl delete -f mysql.yaml
kubectl delete pods <name>
- 显示资源详细信息
kubectl describe nodes <node-name>
kubectl -n admin describe pod 容器
- 查看日志
kubectl logs --tail=20 -f <pod-name> -c <container-name>
- 本地端口转发
kubectl port-forward pod/mysql 3310:3306
- 暴露一个资源作为k8s service
如将mysql pod暴露为一个service:
- kubectl expose pod mysql --port=3306 --name=mysql
- kubectl get svc
- kubectl edit svc mysql 更新 type: NodePort
- kubectl get node -o wide
- kubectl get pod -o wide
- 执行命令
kubectl exec mysql -c mysql -it /bin/bash
kubectl -n admin exec -it 容器 /bin/bash
- 增加 repo
helm repo list
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com
helm repo add elastic https://helm.elastic.co
helm search repo mysql
helm pull --untar stable/mysql
helm install mysql .
helm uninstall mysql
# 不真正执行,只看运行时的 yaml
helm install kfk kafka --dry-run
- Kuboard
- Lens
- KubeSphere
- Wayne
- rancher
- Kubernetes Dashboard
Curl -X Delete https://latency-es.demo.com/latency-2020.11.21