[root@k8s ~]# kubectl describe nodes 127.0.0.1
Name:127.0.0.1
Role:
Labels:beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/hostname=127.0.0.1
Taints:
CreationTimestamp:Fri, 29 Nov 2019 05:46:33 +0800
Phase:
Conditions:
TypeStatusLastHeartbeatTimeLastTransitionTimeReasonMessage
----------------------------------------------------------
OutOfDisk False Fri, 29 Nov 2019 09:47:58 +0800 Fri, 29 Nov 2019 05:46:33 +0800 KubeletHasSufficientDisk kubelet has sufficient disk space available
MemoryPressure False Fri, 29 Nov 2019 09:47:58 +0800 Fri, 29 Nov 2019 05:46:33 +0800 KubeletHasSufficientMemory kubelet has sufficient memory available
DiskPressure False Fri, 29 Nov 2019 09:47:58 +0800 Fri, 29 Nov 2019 05:46:33 +0800 KubeletHasNoDiskPressure kubelet has no disk pressure
Ready True Fri, 29 Nov 2019 09:47:58 +0800 Fri, 29 Nov 2019 05:46:33 +0800 KubeletReady kubelet is posting ready status
Addresses:127.0.0.1,127.0.0.1,127.0.0.1
Capacity:
alpha.kubernetes.io/nvidia-gpu:0
cpu:1
memory:2902952Ki
pods:110
Allocatable:
alpha.kubernetes.io/nvidia-gpu:0
cpu:1
memory:2902952Ki
pods:110
System Info:
Machine ID:c1cc26a06e9e405aa56fa81c7fcc0ca7
System UUID:564DEF43-F784-4106-FBC8-E81C9DC9216F
Boot ID:9df7d476-41e9-412d-bde4-9b9ba119ba25
Kernel Version:3.10.0-123.el7.x86_64
OS Image:CentOS Linux 7 (Core)
Operating System:linux
Architecture:amd64
Container Runtime Version:docker://1.13.1
Kubelet Version:v1.5.2
Kube-Proxy Version:v1.5.2
ExternalID:127.0.0.1
Non-terminated Pods:(11 in total)
NamespaceNameCPU RequestsCPU LimitsMemory RequestsMemory Limits
---------------------------------------------------------------
defaultmysql-05ktg0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-5tvkd0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-dccp50 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-f31950 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-h6h4h0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-hbhhl0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-hws8f0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-jt4sf0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-m8z1d0 (0%)0 (0%)0 (0%)0 (0%)
defaultmysql-xkgcn0 (0%)0 (0%)0 (0%)0 (0%)
defaulttomcat-c59950 (0%)0 (0%)0 (0%)0 (0%)
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.
CPU RequestsCPU LimitsMemory RequestsMemory Limits
--------------------------------------------------
0 (0%)0 (0%)0 (0%)0 (0%)
Events:
FirstSeenLastSeenCountFromSubObjectPathTypeReasonMessage
------------------------------------------------------------
32m32m1{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-vgtbf_default(ae73965a-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-twqs3_default(ae73c4c4-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-x61sl_default(ae7378c1-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-5kmht_default(ae7440a0-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m1{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-rp3pz_default(ae744a31-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-8znqq_default(ae73a01f-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-512rz_default(ae7386c6-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-6vf6j_default(ae73b850-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-cwmlr_default(ae73a8e3-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m32m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-8739b_default(ae73b0a3-1245-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
28m28m1{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-j8s9g_default(3708c328-1246-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
28m28m1{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-rlprq_default(376b8d4e-1246-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-hbhhl_default(b0441080-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-dccp5_default(b043a874-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-05ktg_default(b0442004-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-hws8f_default(b0441a6c-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-xkgcn_default(b04429a8-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-jt4sf_default(b0508921-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-f3195_default(b0759f67-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-5tvkd_default(b0e0a048-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
4m4m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. pod: "mysql-m8z1d_default(b0c00ce6-1249-11ea-ac12-000c29c9216f)". Falling back to DNSDefault policy.
32m4m24{kubelet 127.0.0.1}
2:显示pod的详细信息
kubectl describe pods【pod-name】
示例:
[root@k8s ~]# kubectl describe pods mysql-f3195
Name:mysql-f3195
Namespace:default
Node:127.0.0.1/127.0.0.1
Start Time:Fri, 29 Nov 2019 09:43:49 +0800
Labels:app=mysql
Status:Running
IP:172.17.0.4
Controllers:ReplicationController/mysql
Containers:
mysql:
Container ID:docker://25d5f66e45a3650e8dc054ab3644f73a726b008d2160c8496d72a09832242662
Image:mysql:5.6
Image ID:docker-pullable://docker.io/mysql@sha256:5345afaaf1712e60bbc4d9ef32cc62acf41e4160584142f8d73115f16ad94af4
Port:3306/TCP
State:Running
Started:Fri, 29 Nov 2019 09:44:03 +0800
Ready:True
Restart Count:0
Volume Mounts:
Environment Variables:
MYSQL_ROOT_PASSWORD:123456
Conditions:
TypeStatus
Initialized True
Ready True
PodScheduled True
No volumes.
QoS Class:BestEffort
Tolerations:
Events:
FirstSeenLastSeenCountFromSubObjectPathTypeReasonMessage
------------------------------------------------------------
3m3m1{default-scheduler }NormalScheduledSuccessfully assigned mysql-f3195 to 127.0.0.1
3m3m2{kubelet 127.0.0.1}WarningMissingClusterDNSkubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
3m3m1{kubelet 127.0.0.1}spec.containers{mysql}NormalPulledContainer image "mysql:5.6" already present on machine
3m3m1{kubelet 127.0.0.1}spec.containers{mysql}NormalCreatedCreated container with docker id 25d5f66e45a3; Security:[seccomp=unconfined]
3m3m1{kubelet 127.0.0.1}spec.containers{mysql}NormalStartedStarted container with docker id 25d5f66e45a3
3:显示deployment管理的pod信息
kubectl describe pods 【deployment-name】
七、删除资源对象
1:基于yaml文件删除,-f指定文件
kubectl delete -f 【pod.yaml】
示例:
[root@k8s ~]# kubectl delete -f mysql-rc.yaml
replicationcontroller "mysql" deleted
[root@k8s ~]# kubectl get rc
NAME DESIRED CURRENT READY AGE
tomcat 1 1 1 2h
2:删除所有包含某个label的pod和service
kubectl delete po,svc -l name=【lable-name】
示例:
[root@k8s ~]# kubectl delete po,svc -l app=mysql
pod "mysql-0f7b6" deleted
pod "mysql-0fs9s" deleted
pod "mysql-1zmvc" deleted
pod "mysql-9d6vk" deleted
pod "mysql-gbtvh" deleted
3:删除所有pod
kubectl delete pods --all
示例:
[root@k8s ~]# kubectl delete pods --all
pod "mysql-512rz" deleted
pod "mysql-5kmht" deleted
pod "tomcat-p9x0h" deleted
八、执行容器的命令
1:指定pod的某个容器执行命令
kubectl exec 【pod-name】 uname
示例:
[root@k8s ~]# kubectl exec mysql-0f7b6 uname
Linux
2:进入到pod的容器里
kubectl exec-it 【pod-name】 bash
示例:
[root@k8s ~]# kubectl exec -it mysql-0f7b6 bash
root@mysql-0f7b6:/# ls
bin boot devdocker-entrypoint-initdb.d entrypoint.sh etchome lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
九、查看日志命令
1:查看某个容器日志
kubectl logs 【pod-name】
示例:
[root@k8s ~]# kubectl logs mysql-0f7b6
2019-11-29 01:19:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.46-1debian9 started.
2019-11-29 01:19:10+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2019-11-29 01:19:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.46-1debian9 started.
2019-11-29 01:19:10+00:00 [Note] [Entrypoint]: Initializing database files
2019-11-29 01:19:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-29 01:19:11 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-11-29 01:19:11 0 [Note] /usr/sbin/mysqld (mysqld 5.6.46) starting as process 47 ...
2019-11-29 01:19:11 47 [Note] InnoDB: Using atomics to ref count buffer pool pages
2:动态查看日志,类似于tail-f
kubectl logs -f 【pod-name】
示例:
[root@k8s ~]# kubectl logs -f mysql-0f7b6
2019-11-29 01:20:40 1 [Warning] 'proxies_priv' entry '@ root@mysql-0f7b6' ignored in --skip-name-resolve mode.
2019-11-29 01:20:41 1 [Note] Event Scheduler: Loaded 0 events
2019-11-29 01:20:41 1 [Note] mysqld: ready for connections.
Version: '5.6.46' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)