Executing multiple commands( or from a shell script) in a kubernetes pod

后端 未结 3 2197
生来不讨喜
生来不讨喜 2020-12-18 21:11

I\'m writing a shell script which needs to login into the pod and execute a series of commands in a kubernetes pod.

below is my sample_script.sh

kubect

3条回答
  •  星月不相逢
    2020-12-18 21:22

    -t can solve your task

    For example, I run here few cmd:

    kubectl get pods |grep nginx|cut -f1 -d\  |\
    while read pod; \
     do echo "$pod writing:";\
      kubectl exec -t $pod -- bash -c \
       "dd if=/dev/zero of=/feeds/test.bin bs=260K count=4 2>&1|\
        grep copi |cut -d, -f4; \
        a=$SECONDS; echo -ne 'reading:'; cat /feeds/test.bin >/dev/null ; \
        let a=SECONDS-a ; \
        echo $a sec"
    done
    

    p.s. your example will be:

    kubectl exec -t octavia-api-worker-pod-test -c octavia-api -- bash -c "unset http_proxy https_proxy ; mv /usr/local/etc/octavia/octavia.conf /usr/local/etc/octavia/octavia.conf-orig ; /usr/local/bin/octavia-db-manage --config-file /usr/local/etc/octavia/octavia.conf ; upgrade ; head"
    

提交回复
热议问题