使用go语言做的一个简单的将日志处理成excel的demo。

1、打包二进制

SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64 #arm64、mips64le
go build main.go

二进制执行  ./e2e_excel -logDir /data2/yin/e2e-excel/e2e.log

2、制作成镜像

Dockerfile

FROM XXXXXXubuntu-18.04XXXX

RUN sed -i 's/https/http/g' /etc/apt/sources.list

COPY bin/e2e_excel /
COPY ./run.sh /run.sh
CMD /run.sh

脚本 run.sh 

...
./e2e_excel -logDir ${logDir} && ret=0 || ret=$?

exit ${ret}

构建命令 docker build -t XXXXXXyintest:1.0.0 -f Dockerfile .

3、使用容器运行

docker run  -e logDir=/root/yin/test/e2e.log -v /root/yin/test:/root/yin/test XXXXXXXyintest:1.0.0  bash run.sh

4、使用pod运行

1) 直接apply job.yaml

job.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: yintest-156aa49f4c
  namespace: kube-system
spec:
  backoffLimit: 0
  template:
    metadata:
      name: yintest-156aa49f4c
    spec:
      restartPolicy: Never
      nodeSelector:
        kubernetes.io/hostname: mgt03
      hostNetwork: true
      containers:
      - name: yintest
        image: XXXXXXXXXXXXXyintest:1.0.0
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh","-c","bash +x run.sh"]
        env:
        - name: logDir
          value: /root/yin/test/e2e.log
        resources: {}
        volumeMounts:
        - mountPath: /root/yin/test
          name: trans
      volumes:
      - hostPath:
          path: /root/yin/test
          type: Directory
        name: trans

kubectl apply -f  job.yaml

2) 使用helm部署

helm version 查看环境中部署了helm

├── Chart.yaml
├── templates
│   └── job.yaml
└── values.yaml

values.yaml

global:
  registry: XXXXXXXXXX
  arch: ""
  affinityType: preferred

image:
  yintest:
    name: XXXXX/yintest
    tag: 1.0.0
    architectures: ["amd64","arm64","mips64el"]
  pullPolicy: "IfNotPresent"
logDir: /root/yin/test/

job.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: yintest
  namespace: kube-system
spec:
  backoffLimit: 0
  template:
    metadata:
      name: yintest
    spec:
      restartPolicy: Never
      nodeSelector:
        kubernetes.io/hostname: mgt03
      hostNetwork: true
      containers:
      - name: yintest
        image: {{ .Values.global.registry }}/{{ .Values.image.yintest.name }}{{ .Values.global.arch }}:{{ .Values.image.yintest.tag }}
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh","-c","bash +x run.sh"]
        env:
        - name: logDir
          value: {{ .Values.logDir }}e2e.log
        resources: {}
        volumeMounts:
        - mountPath: {{ .Values.logDir }}
          name: trans
      volumes:
      - hostPath:
          path: {{ .Values.logDir }}
          type: Directory
        name: trans

部署命令:

helm install --debug  yintest helm-demo

卸载 helm uninstall yintest

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐