首页 > 其他分享 >如何在k8s工作节点上,查看容器对应的pod的名字?

如何在k8s工作节点上,查看容器对应的pod的名字?

时间:2022-09-22 13:56:12浏览次数:67  
标签:k8s kubernetes dev properties io pod null 节点 ssc


在k8s中,所有的容器,工作负载,最终都是要运行到节点上的,以容器的方式运行

 

那么,如果要在节点上,查看该节点上运行的容器的pod的名字,pod的信息,该怎么查看?

 

方法非常的简单。

 

1、登录到任意的工作节点

 

2、查看容器的ID

 

4f5de6bafde3就是容器的ID

root@nccztsjb-node-19 ~]# docker ps | grep dev-ssc-ssc 
4f5de6bafde3   reg.yyuap.io:81/yonbip/ssc-ssc          "/usr/bin/dumb-init …"   7 weeks ago    Up 7 weeks              k8s_dev-ssc-ssc_dev-ssc-ssc-78b477b487-z77xz_c87e2267-1001-4c70-bb2a-ab41f3b81aa3_c69a75d3-e339-407c-aa60-424d664dd0da_0
72838c69746a   reg.yyuap.io:81/kubernetes/pause:3.3    "/pause"                 7 weeks ago    Up 7 weeks              k8s_POD_dev-ssc-ssc-78b477b487-z77xz_c87e2267-1001-4c70-bb2a-ab41f3b81aa3_c69a75d3-e339-407c-aa60-424d664dd0da_0
[root@nccztsjb-node-19 ~]# 

 

 

3、查看容器的信息

 

因为该容器是由k8s调度的,kubelet运行的,所以会有一些K8S相关的信息

 

通过docker inspect 命令来查看

 

docker inspect --format='{{index .Config.Labels "io.kubernetes.pod.name"}}' 4f5de6bafde3

 

 

就可以看到容器的pod的名字

[root@nccztsjb-node-19 ~]# docker inspect --format='{{index .Config.Labels "io.kubernetes.pod.name"}}' 4f5de6bafde3
dev-ssc-ssc-78b477b487-z77xz
[root@nccztsjb-node-19 ~]# 

 

 

当然,还可以看到更多的信息

 

[root@nccztsjb-node-19 ~]# docker inspect 4f5de6bafde3 
[
    {
        "Id": "4f5de6bafde3e490da6740bae386e3b5b6319bf616bffae61c707bf36f9af8fc",
        "Created": "2022-08-01T05:34:59.164476102Z",
        "Path": "/usr/bin/dumb-init",
        "Args": [
            "--",
            "entrypoint.sh",
            "catalina.sh",
            "run"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 1350,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-08-01T05:34:59.403013016Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:a15996757a217a10bfd32f546b33d90cdaea98aee9a483cf7126f81c22aef46a",
        "ResolvConfPath": "/data/docker/containers/72838c69746adc497f5ef11aa32e5a409ffa95ea2ff0298c59ddbe363a8a6e33/resolv.conf",
        "HostnamePath": "/data/docker/containers/72838c69746adc497f5ef11aa32e5a409ffa95ea2ff0298c59ddbe363a8a6e33/hostname",
        "HostsPath": "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/etc-hosts",
        "LogPath": "/data/docker/containers/4f5de6bafde3e490da6740bae386e3b5b6319bf616bffae61c707bf36f9af8fc/4f5de6bafde3e490da6740bae386e3b5b6319bf616bffae61c707bf36f9af8fc-json.log",
        "Name": "/k8s_dev-ssc-ssc_dev-ssc-ssc-78b477b487-z77xz_c87e2267-1001-4c70-bb2a-ab41f3b81aa3_c69a75d3-e339-407c-aa60-424d664dd0da_0",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/data/log:/developerMountData/log",
                "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/volumes/kubernetes.io~secret/default-token-tcdsn:/var/run/secrets/kubernetes.io/serviceaccount:ro",
                "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/etc-hosts:/etc/hosts",
                "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/containers/dev-ssc-ssc/96f72e2d:/dev/termination-log"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "container:72838c69746adc497f5ef11aa32e5a409ffa95ea2ff0298c59ddbe363a8a6e33",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "container:72838c69746adc497f5ef11aa32e5a409ffa95ea2ff0298c59ddbe363a8a6e33",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": -997,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "seccomp=unconfined"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 1024,
            "Memory": 2147483648,
            "NanoCpus": 0,
            "CgroupParent": "/kubepods/podc69a75d3-e339-407c-aa60-424d664dd0da",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 100000,
            "CpuQuota": 100000,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 2147483648,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/asound",
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/data/docker/overlay2/cd4896984a0be3ca5db5fbe686e7e5ff9d9274572e08e260f2a17c87e85aad6c-init/diff:/data/docker/overlay2/753f011a551637a19e5c7d92ba371e91fbbadb9fe2be5e9b175a0ecc3f7125c4/diff:/data/docker/overlay2/9a791305c782ffa259df2c393c34cba4e0987132e2b53b725676b8d660c9d578/diff:/data/docker/overlay2/66b1d7268215c8a3389af8a7f76d06ed134ebd09c092b5a2c2aa6e52bb33b23d/diff:/data/docker/overlay2/c95263219f555b844da582dd2d92883b2fae8e51998901d6bca34076c521346d/diff:/data/docker/overlay2/75bb3dbf7999568fda45991901df910dbb225d17862d242fc49a5a31095c467d/diff:/data/docker/overlay2/f08c31461a9196402af32aacbed7f620950af56d6ab0693bcd421f4a2d79dadb/diff:/data/docker/overlay2/4d009af171505cd397bc150d3d3228236a0be2c099f08f260493848dc1bea761/diff",
                "MergedDir": "/data/docker/overlay2/cd4896984a0be3ca5db5fbe686e7e5ff9d9274572e08e260f2a17c87e85aad6c/merged",
                "UpperDir": "/data/docker/overlay2/cd4896984a0be3ca5db5fbe686e7e5ff9d9274572e08e260f2a17c87e85aad6c/diff",
                "WorkDir": "/data/docker/overlay2/cd4896984a0be3ca5db5fbe686e7e5ff9d9274572e08e260f2a17c87e85aad6c/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/etc-hosts",
                "Destination": "/etc/hosts",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/containers/dev-ssc-ssc/96f72e2d",
                "Destination": "/dev/termination-log",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/data/log",
                "Destination": "/developerMountData/log",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/c69a75d3-e339-407c-aa60-424d664dd0da/volumes/kubernetes.io~secret/default-token-tcdsn",
                "Destination": "/var/run/secrets/kubernetes.io/serviceaccount",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "dev-ssc-ssc-78b477b487-z77xz",
            "Domainname": "",
            "User": "0",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8888/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "cf_disconf_user_define_download_dir_ncc_common=/",
                "cf_disconf_env_ncc_common=dev",
                "developer_hubble_apm=true",
                "MALLOC_ARENA_MAX=1",
                "LOG_INSTANCE_ID=dev-ssc-ssc-78b477b487-z77xz",
                "iris.serviceUrl.defaultZone=http://172.20.45.214:80/registry-0/eureka/",
                "DNS_SERVER=default",
                "dc_k8s_namespace=c87e2267-1001-4c70-bb2a-ab41f3b81aa3",
                "dc_k8s_terminate_seconds=360",
                "cf_disconf_user_define_config_path_dir_ncc_common={}",
                "FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS=true",
                "disconf.conf_server_host=http://172.20.45.214:80/confcenter",
                "cf_disconf_conf_server_host=http://172.20.45.214/confcenter",
                "cf_clientAccessKey=fuaJUwsE69mccrCl",
                "hubble_agent_url=http://172.20.45.214:80/download/hubble-agent.jar",
                "dc_app_env=dev",
                "access.secret=evQeAcSH8jm2UysqVNbsNvDEG4a0C8",
                "INSTANCE_HOST_IP=172.20.45.40",
                "hubble_collect_url=http://172.20.45.214:80",
                "cf_disconf_version=1.0.0",
                "http_read_timeout=1200000",
                "isPremises=true",
                "podIP=172.23.37.7",
                "enable_jmx_monitor=true",
                "PORT=80",
                "dc_hostname=http://172.20.45.214",
                "developer_app_logs=c87e2267-1001-4c70-bb2a-ab41f3b81aa3;dev-ssc-ssc;/usr/local/tomcat/webapps/ROOT/WEB-INF/home/nclogs/",
                "dc_app_name=ssc-ssc",
                "dc_k8s_dns_policy=ClusterFirst",
                "cf_disconf_version_ncc_common=1.0.0",
                "dc_k8s_svc_name=dev-ssc-ssc",
                "dc_app_code=ssc-ssc",
                "HOST=dev-ssc-ssc.prod1.yonyoucloud-k8s.com",
                "JAVA_OPTS=-server -Xms512m -Xmx1792m -Xss8m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=768m -Duser.timezone=GMT+08 -Dfile.encoding=UTF8 -Dsun.jnu.encoding=UTF8 -Djava.awt.headless=true -XX:+DisableExplicitGC -Xbootclasspath/a:/usr/local/tomcat/webapps/ROOT/WEB-INF/home/yonyou-yyy-agent/probes/boot/boot.jar -javaagent:/usr/local/tomcat/webapps/ROOT/WEB-INF/home/yonyou-yyy-agent/probes/yonyou-yyy.jar",
                "cf_disconf_user_define_confing_file=authority.json,cbdegrade.json,moblie_imagescan.xml,strategy.json",
                "cf_disconf_download_order_ncc_common=2",
                "cf_disconf_app=ssc-ssc",
                "mw_profiles_active=dev",
                "cf_disconf_env=dev",
                "access.key=fuaJUwsE69mccrCl",
                "cf_disconf_user_define_download_dir=/",
                "cf_disconf_app_ncc_common=ncc-common",
                "LOG4J_log4j2_formatMsgNoLookups=true",
                "cf_clientAccessSecret=evQeAcSH8jm2UysqVNbsNvDEG4a0C8",
                "cf_disconf_user_define_confing_file_ncc_common=ca1.js,caRegisterCenter.xml,datawork.xml,dbdriverset.xml,dbmerge.properties,esn.properties,eureka.properties,gray.properties,group-mapping.properties,intelliv.properties,iTrusServerConfig.properties,iuap-licenseclient-conf.properties,key.properties,lock-conf.properties,logger-config.properties,macloud.properties,miscellaneous.xml,mq.properties,msconfig-public.properties,nccssoConfig.xml,nlinkpe.properties,nmc.properties,obmconfig.properties,prop.xml,redis-config.xml,safehost.properties,server.xml,shutdown.sh,signature.xml,tenantinfo.properties,ufs.properties,ufs_net.properties",
                "registry=http://172.20.45.214:80",
                "KUBERNETES_PORT_443_TCP_PORT=443",
                "KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
                "KUBERNETES_SERVICE_HOST=10.96.0.1",
                "KUBERNETES_SERVICE_PORT=443",
                "KUBERNETES_SERVICE_PORT_HTTPS=443",
                "KUBERNETES_PORT=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP_PROTO=tcp",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/java/bin:/usr/local/tomcat/lib:/usr/local/tomcat/bin",
                "LANG=zh_CN.UTF-8",
                "LANGUAGE=zh_CN.UTF-8",
                "LC_CTYPE=zh_CN.UTF-8",
                "LC_ALL=zh_CN.UTF-8",
                "TZ=Asia/Shanghai",
                "JAVA_MAJOR=8",
                "WORKDIR=/usr/local/tomcat",
                "BASE_IMAGE=tomcat:9.0.53-jdk8-alpine",
                "TOMCAT_VERSION=9.0.53",
                "JAVA_VERSION=8u202",
                "GLIBC_VERSION=2.33-r0",
                "JAVA_HOME=/usr/local/java",
                "CATALINA_HOME=/usr/local/tomcat",
                "CLASSPATH=/usr/local/java/lib/dt.jar:/usr/local/java/lib/tools.jar"
            ],
            "Cmd": [
                "catalina.sh",
                "run"
            ],
            "Healthcheck": {
                "Test": [
                    "NONE"
                ]
            },
            "Image": "reg.yyuap.io:81/yonbip/ssc-ssc@sha256:a0d5931b540f4c6bc87b0b2b6f4280ec8396ae275a8021f2557620ccb45919e2",
            "Volumes": null,
            "WorkingDir": "/usr/local/tomcat/webapps",
            "Entrypoint": [
                "/usr/bin/dumb-init",
                "--",
                "entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "annotation.io.kubernetes.container.hash": "45e7140c",
                "annotation.io.kubernetes.container.ports": "[{\"containerPort\":8888,\"protocol\":\"TCP\"}]",
                "annotation.io.kubernetes.container.preStopHandler": "{\"exec\":{\"command\":[\"/bin/sh\",\"-c\",\"if [[ -f /bin/offline.sh ]]; then /bin/offline.sh;fi; if [[ -f /bin/shutdown.sh ]]; then /bin/shutdown.sh; fi\"]}}",
                "annotation.io.kubernetes.container.restartCount": "0",
                "annotation.io.kubernetes.container.terminationMessagePath": "/dev/termination-log",
                "annotation.io.kubernetes.container.terminationMessagePolicy": "File",
                "annotation.io.kubernetes.pod.terminationGracePeriod": "360",
                "io.kubernetes.container.logpath": "/var/log/pods/c87e2267-1001-4c70-bb2a-ab41f3b81aa3_dev-ssc-ssc-78b477b487-z77xz_c69a75d3-e339-407c-aa60-424d664dd0da/dev-ssc-ssc/0.log",
                "io.kubernetes.container.name": "dev-ssc-ssc",
                "io.kubernetes.docker.type": "container",
                "io.kubernetes.pod.name": "dev-ssc-ssc-78b477b487-z77xz",
                "io.kubernetes.pod.namespace": "c87e2267-1001-4c70-bb2a-ab41f3b81aa3",
                "io.kubernetes.pod.uid": "c69a75d3-e339-407c-aa60-424d664dd0da",
                "io.kubernetes.sandbox.id": "72838c69746adc497f5ef11aa32e5a409ffa95ea2ff0298c59ddbe363a8a6e33"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {}
        }
    }
]
[root@nccztsjb-node-19 ~]# 
 

 

  • namespace的名字
  • pod的名字
  • prestop脚本
  • 容器的名字

 

很多的k8s给加上去的信息都是可以查看到的!

标签:k8s,kubernetes,dev,properties,io,pod,null,节点,ssc
From: https://www.cnblogs.com/chuanzhang053/p/16718981.html

相关文章

  • kafka之单节点多Broker部署及使用
    (1)单节点建立多Broker的集群多个server.properties文件表示多个Broker,一个server.properties文件对应一个Brokercpserver.propertiesserver-1.properties(复制一个......
  • Kafka单节点单broker部署及使用
    1.Kafka单节点单broker部署及使用(1)配置Kafka的config目录下的server.properties文件进入$KAFKA_HOME/config/serverpropertiesvim serverproperties主要......
  • k8s 无头服务
    目录k8s无头服务无头服务是什么k8s无头服务无头服务是什么无头服务根据我自己的理解来说,我们访问一个服务正常是访问的4层代理service或者7层代理ingress。而无头服务就......
  • 基于Kuboard实现k8s单master集群安装
    一、安装要求采用Kuboard方式安装有一定的安装要求:至少2台 2核4G 的服务器CentOS7.6/7.7/7.8/7.9kubernetesv1.19.x版本采用的Docker,而之上的版本使用的是......
  • 万节点规模云服务的 SRE 能力建设
    简介: 随着越来越多企业以容器作为系统底座,那么阿里云的云服务又是如何进行SRE规划呢?下文将由资深SRE工程师拆解2万节点规模云服务背后的SRE能力建设,立即点击观看!......
  • Sqlserver 根据父节点ID查询所有子节点
    举例:    根据父节点ID查询出所有子节点不含父节点DECLARE@ParentIDintSET@ParentID='3';withCTEGetChildas(select*from[dbAssetCheck-yili].[d......
  • Kubernetes(K8S)特性有哪些?
    Kubernetes简介Kubernetes是一个开源的,用于管理云平台中做个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单且高效,Kubernetes提供了应用部署,规划,更新......
  • POD的生命周期
    POD的生命周期#删除所有的pod[root@k8s-m01~]#kubectldeletepod--all##initcontainer初始化容器是指,在主容器启动之前,我们可以让他做一些准备工作。比如:1.......
  • k8s-安装教程
    kubelet版本过高,v1.24版本后kubernetes放弃docker了,所以我们安装1.24以下的。以下操作三台主机都要做。#关闭防火墙systemctlstopfirewalld&&systemctldisablefire......
  • k8s中配置存储ConfigMap和Secret
    ConfigMapConfigMap是一种比较特殊的存储卷,它的主要作用是用来存储配置信息的。Secret在kubernetes中,还存在一种和ConfigMap非常类似的对象,称为Secret对象。它主要用......