生产上,有时候为了便于调试,会需要用到一些dig curl等工具,这里提供一个很好用的 docker image

集成了如下工具:

  • tcpdump
  • htop
  • curl
  • grpcurl
  • httpstat
  • iftop
  • wget
  • strace
  • nmap
  • tar
  • dig
  • mysql-client
  • redis-client
  • iproute2
  • jq

 

具体的Dockerfile如下:

FROM golang:alpine as grpcurl
RUN apk update \
  && apk add --virtual build-dependencies git \
  && apk add bash curl jq \
  && go get -u github.com/fullstorydev/grpcurl \
  && go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

FROM alpine:latest
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
    apk update && \
    apk add --no-cache vim bash tcpdump curl wget strace mysql-client iproute2 redis jq iftop tzdata tar nmap bind-tools htop && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN wget -O /usr/bin/httpstat https://github.com/davecheney/httpstat/releases/download/v1.0.0/httpstat-linux-amd64-v1.0.0 && \
    chmod +x /usr/bin/httpstat
COPY --from=grpcurl  /go/bin/grpcurl /usr/bin/grpcurl
ENV TZ=Asia/Shanghai LC_ALL=C.UTF-8 LANG=C.UTF-8 LANGUAGE=C.UTF-8
ENTRYPOINT [ "/bin/bash" ]

 

yaml工程师上手,弄到K8s去!

# cat debug-utils.deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: debug-utils
  labels:
    name: debug-utils
spec:
  selector:
    matchLabels:
      app: debug-utils
  replicas: 1
  template:
    metadata:
      labels:
        app: debug-utils
    spec:
      containers:
      - name: debug-utils
        image: registry.gitlab.xxxxx.cn/arch/base-images/debug-utils:latest
        command:
          - "sh"
          - "-c"
          - >
            while true; do
              sleep 3600;
            done
        imagePullPolicy: IfNotPresent
        name: curl-client
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: gitlab-registry
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

 

 

参考:

如何用K8S临时容器来调试pods (qq.com)