标签:特殊用法 amp exp accounts flags sql cap configure url
[root@k8s ~]# kubectl get pod tomcat-p9x0h NAME READY STATUS RESTARTS AGE tomcat-p9x0h 1/1 Running 0 1h
一、资源对象类型列表
名称 简写 componentsstatuses cs daemonsets ds deployment deploy events ev endpoints ep horizontalpodautoscalers hpa ingresses ing jobs limitranges limits nodes no namspaces ns pods po persistentvolumes pv persistentvolumeclaims pvc resourcequotas quota replicationcontrollers rc secrets serviceaccounts sa services svc
二、特殊用法
[root@k8s ~]# kubectl get pods tomcat-p9x0h mysql-19h65 NAME READY STATUS RESTARTS AGE tomcat-p9x0h 1/1 Running 0 1h mysql-19h65 1/1 Running 0 2h
2:同时查询pod、rc信息
[root@k8s ~]# kubectl get pod/tomcat-p9x0h rc/mysql NAME READY STATUS RESTARTS AGE po/tomcat-p9x0h 1/1 Running 0 1h NAME DESIRED CURRENT READY AGE rc/mysql 1 1 1 2h
3:同时创建rc、svc
[root@k8s ~]# kubectl create -f mysql-rc.yaml -f mysql-svc.yaml replicationcontroller "mysql" created service "mysql" created
输出格式 说明 custom-columns=<spec> 根据自定义列名进行输出,逗号分隔 custom-columns-file=<filename> 从文件中获取自定义列名进行输出 json 以JSON格式显示结果 jsonpath=<template> 输出jasonpath表达式定义的字段信息 jasonpath-file=<filename> 输出jsonpath表达式定义的字段信息,来源于文件 name 仅输出资源对象的名称 wide 输出更多信息,比如会输出node名 yaml 以yaml格式输出
[root@k8s ~]# kubectl create -f mysql-rc.yaml -f mysql-svc.yaml replicationcontroller "mysql" created service "mysql" created
2:可以指定一个目录,这样可以一次性根据该目录下所有yaml或json文件定义资源
[root@k8s ~]# kubectl create -f /data/k8s-yaml-root/ replicationcontroller "mysql" created service "mysql" created
[root@k8s ~]# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-512rz 1/1 Running 0 2m mysql-5kmht 1/1 Running 0 2m tomcat-p9x0h 1/1 Running 0 2h
2:查看rc和service
[root@k8s ~]# kubectl get rc,svc NAME DESIRED CURRENT READY AGE rc/mysql 10 10 10 4m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes 10.254.0.1 <none> 443/TCP 4h svc/mysql 10.254.244.102 <none> 3306/TCP 4m svc/tomcat 10.254.250.150 <nodes> 8080:30001/TCP 2h
[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: <none> CreationTimestamp: Fri, 29 Nov 2019 05:46:33 +0800 Phase: Conditions: Type Status LastHeartbeatTime LastTransitionTime Reason Message ---- ------ ----------------- ------------------ ------ ------- 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) Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits --------- ---- ------------ ---------- --------------- ------------- default mysql-05ktg 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-5tvkd 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-dccp5 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-f3195 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-h6h4h 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-hbhhl 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-hws8f 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-jt4sf 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-m8z1d 0 (0%) 0 (0%) 0 (0%) 0 (0%) default mysql-xkgcn 0 (0%) 0 (0%) 0 (0%) 0 (0%) default tomcat-c5995 0 (0%) 0 (0%) 0 (0%) 0 (0%) Allocated resources: (Total limits may be over 100 percent, i.e., overcommitted. CPU Requests CPU Limits Memory Requests Memory Limits ------------ ---------- --------------- ------------- 0 (0%) 0 (0%) 0 (0%) 0 (0%) Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 32m 32m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 32m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 28m 28m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 28m 28m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 4m 4m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet 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. 32m 4m 24 {kubelet 127.0.0.1}
[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: <none> Environment Variables: MYSQL_ROOT_PASSWORD: 123456 Conditions: Type Status Initialized True Ready True PodScheduled True No volumes. QoS Class: BestEffort Tolerations: <none> Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 3m 3m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-f3195 to 127.0.0.1 3m 3m 2 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 3m 3m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulled Container image "mysql:5.6" already present on machine 3m 3m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Created Created container with docker id 25d5f66e45a3; Security:[seccomp=unconfined] 3m 3m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Started Started container with docker id 25d5f66e45a3
3:显示deployment管理的pod信息
[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
[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
[root@k8s ~]# kubectl delete pods --all pod "mysql-512rz" deleted pod "mysql-5kmht" deleted pod "tomcat-p9x0h" deleted
[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 dev docker-entrypoint-initdb.d entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[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
[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)
标签:特殊用法 amp exp accounts flags sql cap configure url
原文地址:https://www.cnblogs.com/douyi/p/11980060.html