- 帮忙
kubectl help
- 版本信息
[root@host ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:52:00Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
- 显示集群信息(查看 master 节点)
root@host ~]# kubectl cluster-info
Kubernetes master is running at https://192.168.31.27:6443
KubeDNS is running at https://192.168.31.27:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
- 查看节点列表
[root@host68 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
host68 Ready master 131d v1.18.3
host69 Ready <none> 70d v1.18.6
host70 Ready <none> 38d v1.18.3
host71 Ready <none> 70d v1.18.6
host72 Ready <none> 66d v1.18.3
host73 Ready <none> 66d v1.18.3
host74 Ready <none> 126d v1.18.3
- 查看所有 pod 和 namespace
[root@vip-068 ~]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default gitlab-86hgh 1/1 Running 0 124d
default mysql-qqghr 1/1 Running 0 129d
es es-46tml 1/1 Running 0 37d
es es-5twv5 1/1 Running 1 37d
es es-g4tnp 1/1 Running 0 29d
es es-vx9r9 1/1 Running 0 30d
es es-xj8kk 1/1 Running 0 27d
- 列出所有 node 和 pod
kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName --all-namespaces
- 查看某个 pod 外面的容器
[root@host68 ~]# kubectl -n es get pod es-46tml -o jsonpath="{.spec['containers','initContainers'][*].name}"
es
# 或者
kubectl -n es describe pod es-46tml
- 列出某个容器外面的目录
# 命令
kubectl -n <namespace> -c <container> exec <pod_name> -- ls -la /
# 示例
kubectl -n es -c es exec es-46tml -- ls -la /usr/share/elasticsearch/config
[root@host68 ~]# kubectl -n es -c es exec es-46tml -- ls -la /usr/share/elasticsearch/config
total 1360
drwxrwxr-x 1 elasticsearch root 4096 Oct 12 13:28 .
drwxrwxr-x 1 elasticsearch root 4096 Sep 5 06:03 ..
-rw-rw---- 1 elasticsearch root 199 Sep 5 06:03 elasticsearch.keystore
-rw-rw---- 1 elasticsearch root 53 May 28 16:33 elasticsearch.yml
-rw-rw---- 1 elasticsearch root 2301 May 28 16:28 jvm.options
drwxrwxr-x 2 elasticsearch root 4096 May 28 16:31 jvm.options.d
-rw-rw---- 1 elasticsearch root 7860 May 28 16:33 log4j2.properties
-rw-rw---- 1 elasticsearch root 473 May 28 16:32 role_mapping.yml
-rw-rw---- 1 elasticsearch root 197 May 28 16:32 roles.yml
-rw-r--r-- 1 root root 1345763 Oct 12 13:28 synonym.txt
-rw-rw---- 1 elasticsearch root 0 May 28 16:32 users
-rw-rw---- 1 elasticsearch root 0 May 28 16:32 users_roles
- 删除容器外面的文件
kubectl -n es -c es exec es-46tml -- rm /usr/share/elasticsearch/config/synonym.txt
- 创立目录
kubectl -n es -c es exec es-46tml -- mkdir /usr/share/elasticsearch/config/analysis
- 拷贝文件到容器目录
# 拷贝
kubectl -n es -c es cp synonym.txt es-46tml:/usr/share/elasticsearch/config/analysis
# 查看
[root@host68 test]# kubectl -n es -c es exec es-46tml -- ls -la /usr/share/elasticsearch/config/analysis
total 1324
drwxr-xr-x 2 root root 4096 Oct 13 05:57 .
drwxrwxr-x 1 elasticsearch root 4096 Oct 13 05:56 ..
-rw-r--r-- 1 root root 1345763 Oct 13 05:57 synonym.txt
qbit snap