简介

参考百度百科

BusyBox 是一个集成了三百多个最常用Linux命令和工具的软件。

BusyBox 包含了一些简单的工具,例如ls、cat和echo等等,还包含了一些更大、更复杂的工具,例grep、find、mount以及telnet。

有些人将 BusyBox 称为 Linux 工具里的瑞士军刀。

简单的说BusyBox就好像是个大工具箱,它集成压缩了 Linux 的许多工具和命令,也包含了 Linux 系统的自带的shell。



k8s中运行busybox_标准输入


前台运行BusyBox

1.28:docker pull registry.cn-chengdu.aliyuncs.com/qzcsbj/busybox:1.28

1.34

方式一:kubectl run

不常用,因为如果要写很多参数不方便

kubectl run -h

# Start the nginx pod using a different command and custom arguments
kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>



每3600秒RESTART 

kubectl run busybox --image=busybox:1.34 --command -- sleep 3600

如果设置的是60秒

k8s中运行busybox_linux_02


方式二:从标准输入创建

cat << EOF的意思是以EOF输入字符为标准输入结束,就是当你输入cat << EOF的时候,你可以随意输入字符,但是当输入EOF的时候就结束了。

cat<<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
spec:
containers:
- name: busybox
image: busybox:1.34
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
EOF



或者:

# 从标准输入创建多个 YAML 对象
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep
spec:
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000000"
---
apiVersion: v1
kind: Pod
metadata:
name: busybox-sleep-less
spec:
containers:
- name: busybox
image: busybox
args:
- sleep
- "1000"
EOF



方式三:yaml资源文件

command会覆盖容器默认要执行的命令,也就是Dokcerfile里面的CMD

可能找不到终端,所以需要指定sh(也可以写为/bin/sh)或者bash

-c,command,后面跟上要执行的命令

apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox:1.34
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
imagePullPolicy: IfNotPresent



或者

command: ["sh","-c","sleep 3600"]



其它参考

​https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use​

command: ['sh', '-c', 'echo The app is running! && sleep 3600']

apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]





============================= 提升自己 ==========================

:如有侵权,请联系删除。

============================= 升职加薪 ==========================