【发布时间】:2019-12-29 15:56:49
【问题描述】:
在 minikube hyper-v 机器上,我使用 sawtooth config file 部署了锯齿形 0。
现在,当我检查正在运行的 pod 时,它似乎有一些默认的,但在尝试连接 kubernetes shell 容器时。
C:\Users\Debo>kubectl get --all-namespaces
You must specify the type of resource to get. Use "kubectl api-resources" for a complete list of supported resources.
error: Required resource not specified.
Use "kubectl explain <resource>" for a detailed description of that resource (e.g. kubectl explain pods).
See 'kubectl get -h' for help and examples
C:\Users\Debo>kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default sawtooth-0-65d547498c-mfrsb 7/7 Running 1 120m
kube-system coredns-6955765f44-b684l 1/1 Running 0 122m
kube-system coredns-6955765f44-tc4vg 1/1 Running 0 122m
kube-system etcd-minikube 1/1 Running 0 121m
kube-system kube-addon-manager-minikube 1/1 Running 0 121m
kube-system kube-apiserver-minikube 1/1 Running 0 121m
kube-system kube-controller-manager-minikube 1/1 Running 0 121m
kube-system kube-proxy-t7nhs 1/1 Running 0 122m
kube-system kube-scheduler-minikube 1/1 Running 0 121m
kube-system storage-provisioner 1/1 Running 0 122m
kubernetes-dashboard dashboard-metrics-scraper-7b64584c5c-b8t7s 1/1 Running 0 122m
kubernetes-dashboard kubernetes-dashboard-79d9cd965-pn94z 1/1 Running 0 122m
C:\Users\Debo>kubectl get pods
NAME READY STATUS RESTARTS AGE
sawtooth-0-65d547498c-mfrsb 7/7 Running 1 120m
C:\Users\Debo>kubectl exec -it $(kubectl get pods | awk "/sawtooth-0/ {print $1}") --container sawtooth-shell -- bash
awk: /sawtooth-0/ {print $1})
awk: ^ syntax error
errcount: 1
Error from server (NotFound): pods "$(kubectl" not found
C:\Users\Debo>
【问题讨论】:
-
尝试使用单引号中的
awk命令 -awk '/sawtooth-0/ {print $1}'或执行awk "/sawtooth-0/ {print \$1}" -
``` C:\Users\Debo>kubectl exec -it $(kubectl get pods | awk '/sawtooth-0/ {print $1}') --container sawtooth-shell -- bash awk: '/sawtooth-0/ awk: ^ invalid char ''' in expression Error from server (NotFound): pods "$(kubectl" not found C:\Users\Debo>kubectl exec -it $(kubectl get pods | awk "/sawtooth-0/ {print \$1}") --container sawtooth-shell -- bash awk: /sawtooth-0/ {print \$1}) awk: ^ 反斜杠不是最后一个字符来自服务器的错误(未找到): pods "$(kubectl" not found ``` 不工作兄弟
-
这看起来像 Windows 命令提示符,但 Unix Bourne shell 语法。您实际使用的是什么 shell,它是否支持 Bourne shell
$(command)替换语法? -
(
kubectl get pods -o name可能比awk调用更健壮;还可以考虑按标签kubectl get pods -l app=sawtooth或类似方法进行过滤,以避免需要awk/grep/sed步骤。 ) -
您到底想达到什么目标? Kubernetes 有许多内置命令。如果您想从锯齿 pod 连接到特定容器,您可以使用
kubectl exec -ti sawtooth-0-65d547498c-mfrsb -c <container_name> /bin/bash
标签: awk kubernetes hyperledger minikube hyperledger-sawtooth