zoukankan      html  css  js  c++  java
  • 如何批量查看容器内部的进程?

    脚本如下

    #!/usr/bin/env bash
    [[ -n $DEBUG ]] && set -x
    set -ou pipefail
    
    useage() {
        cat <<HELP
    USAGE:
        kces.sh CMDLINE
    HELP
    }
    
    exit_err() {
        echo >&2 "${1}"
        exit 1
    }
    
    if [ $# -lt 1 ]; then
        useage
        exit 1
    fi
    CMDLINE=$@
    kubectl get pod --field-selector=status.phase==Running -o custom-columns='NAME:metadata.name,CONTAINER:spec.containers[*].name' --no-headers | while read -r line;do
        arr=(${line/,/ })
        num=${#arr[@]}
        for ((i=1;i<num;i++));do
            pod="${arr[0]}"
            container="${arr[i]}"
            echo "[${pod}/${container}]"
            kubectl exec "${pod}" -c "${container}" ${CMDLINE}
            echo -e "
    "
        done
    done
    

    使用举例

    kubens istio-system
    kces cat /proc/1/cmdline
    

    使用效果

    [istio-citadel-59c5db9b77-bsk9x/citadel]
    /usr/local/bin/istio_ca--self-signed-ca--append-dns-names=true--grpc-port=8060--citadel-storage-namespace=istio-system--custom-dns-names=istio-pilot-service-account.istio-system:istio-pilot.istio-system--monitoring-port=15014--self-signed-ca=true--workload-cert-ttl=2160h
    
    [istio-galley-f469f7d4f-x8kv7/galley]
    /usr/local/bin/galleyserver--meshConfigFile=/etc/mesh-config/mesh--livenessProbeInterval=1s--livenessProbePath=/healthliveness--readinessProbePath=/healthready--readinessProbeInterval=1s--deployment-namespace=istio-system--insecure=true--validation-webhook-config-file/etc/config/validatingwebhookconfiguration.yaml--monitoringPort=15014--log_output_level=default:info
    
    [istio-ingressgateway-6c89d587bf-5grvl/istio-proxy]
    /usr/local/bin/pilot-agentproxyrouter--domainistio-system.svc.cluster.local--log_output_level=default:info--drainDuration45s--parentShutdownDuration1m0s--connectTimeout10s--serviceClusteristio-ingressgateway--zipkinAddressjaeger-collector.istio-system.svc:9411--proxyAdminPort15000--statusPort15020--controlPlaneAuthPolicyNONE--discoveryAddressistio-pilot:15010
    
    [istio-pilot-5bb797c4bb-sjn6n/discovery]
    /usr/local/bin/pilot-discoverydiscovery--monitoringAddr=:15014--log_output_level=default:info--domaincluster.local--secureGrpcAddr--keepaliveMaxServerConnectionAge30m
    
    [istio-pilot-5bb797c4bb-sjn6n/istio-proxy]
    /usr/local/bin/pilot-agentproxy--domainistio-system.svc.cluster.local--serviceClusteristio-pilot--templateFile/etc/istio/proxy/envoy_pilot.yaml.tmpl--controlPlaneAuthPolicyNONE
    
    [istio-policy-86b448c565-5prs6/mixer]
    OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: "cat": executable file not found in $PATH": unknown
    command terminated with exit code 126
    
    
    [istio-policy-86b448c565-5prs6/istio-proxy]
    /usr/local/bin/pilot-agentproxy--domainistio-system.svc.cluster.local--serviceClusteristio-policy--templateFile/etc/istio/proxy/envoy_policy.yaml.tmpl--controlPlaneAuthPolicyNONE
    
    [istio-sidecar-injector-d98dbbb8b-wbshm/sidecar-injector-webhook]
    /usr/local/bin/sidecar-injector--caCertFile=/etc/istio/certs/root-cert.pem--tlsCertFile=/etc/istio/certs/cert-chain.pem--tlsKeyFile=/etc/istio/certs/key.pem--injectConfig=/etc/istio/inject/config--meshConfig=/etc/istio/config/mesh--healthCheckInterval=2s--healthCheckFile=/health
    
    [istio-telemetry-676c67ff64-ftd4s/mixer]
    OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: "cat": executable file not found in $PATH": unknown
    command terminated with exit code 126
    
    
    [istio-telemetry-676c67ff64-ftd4s/istio-proxy]
    /usr/local/bin/pilot-agentproxy--domainistio-system.svc.cluster.local--serviceClusteristio-telemetry--templateFile/etc/istio/proxy/envoy_telemetry.yaml.tmpl--controlPlaneAuthPolicyNONE
    
    [jaeger-collector-8698b58b55-qdh4z/jaeger-collector]
    OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: "cat": executable file not found in $PATH": unknown
    command terminated with exit code 126
    
    
    [jaeger-operator-66ff476758-v8s7x/jaeger-operator]
    /usr/local/bin/jaeger-operatorstart
    
    [jaeger-query-7f9c7c84c-mpshg/jaeger-query]
    OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: "cat": executable file not found in $PATH": unknown
    command terminated with exit code 126
    
    
    [jaeger-query-7f9c7c84c-mpshg/jaeger-agent]
    OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: "cat": executable file not found in $PATH": unknown
    command terminated with exit code 126
    
    
  • 相关阅读:
    setTimeOut与循环闭包问题
    ES6----class用法
    JS------对象的继承方式
    JavaScript对象 -构建
    nodejs异步---Async
    mongdb位置索引
    mongodb 索引3
    mongod 索引2
    mongodb 索引1
    3 C++数据类型
  • 原文地址:https://www.cnblogs.com/futuretea/p/12144662.html
Copyright © 2011-2022 走看看