我的问题很简单.
如何在pod中执行bash命令?我想用一条bash命令完成所有的事情?
kubectl exec -it --namespace="tools" mongo-pod --bash -c "mongo"
Error: unknown flag: --bash
所以,这个命令被简单地忽略了。
kubectl exec -it --namespace="tools" mongo-pod bash -c "mongo"
root@mongo-deployment-78c87cb84-jkgxx:/#
或者。
kubectl exec -it --namespace="tools" mongo-pod bash mongo
Defaulting container name to mongo.
Use 'kubectl describe pod/mongo-deployment-78c87cb84-jkgxx -n tools' to see all of the containers in this pod.
/usr/bin/mongo: /usr/bin/mongo: cannot execute binary file
command terminated with exit code 126
如果它只是一个 bash,它肯定有效。但我想立即跳入 mongo shell。
我该怎么办啊,求思路?
双重破折号"--"是用来分隔你想在容器内运行的命令和kubectl参数的,所以正确的方法是:
kubectl exec -it --namespace=tools mongo-pod -- bash -c "mongo"
你在"--"和"bash"之间忘了一个空格。
要执行多个命令话,你可能想:
比如:
apiVersion: v1 kind: Pod metadata: name: init-demo spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - name: workdir mountPath: /usr/share/nginx/html # These containers are run during pod initialization initContainers: - name: install image: busybox command: - wget - "-O" - "/work-dir/index.html" - http://info.cern.ch volumeMounts: - name: workdir mountPath: "/work-dir" dnsPolicy: Default volumes: - name: workdir emptyDir: {}
我粗心了,感谢!
你的答案