kubernetes 服务器错误(NotFound):pod "$(kubectl"未找到

eaf3rand  于 2023-01-01  发布在  Kubernetes
关注(0)|答案(1)|浏览(432)

在minikube hyper-v机器上,我使用sawtooth config file部署了锯齿波0。
现在,当我检查运行的pod时,它似乎有一些默认的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>
ajsxfq5m

ajsxfq5m1#

如果我理解您的用例,您正尝试从名称空间中的给予pod列表中过滤锯齿-0 pod,然后打开一个交互式会话,指向在其中运行的容器,您知道容器名称。

因此,为了解决上述问题,我将锯齿配置文件附加在问题中,并启动了锯齿0和锯齿1的两个示例以及一些虚拟pod,然后我在windows power shell上使用此命令过滤并连接到锯齿0 pod上的容器。

以下所有操作均假定您需要在windows powershell上运行kubectl

PS C:\Users\winuser> kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
busybox                       1/1     Running   0          4m18s
nginx                         1/1     Running   0          10m
sawtooth-0-7f584587cf-8jfwk   7/7     Running   0          19m
sawtooth-1-6ccd4494-kq24n     7/7     Running   0          18m

连接到锯齿波-0

PS C:\Users\winuser> kubectl exec -it $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | findstr -i sawtooth-0) --container sawtooth-shell -- bash
root@sawtooth-0-7f584587cf-8jfwk:/# whoami
root
root@sawtooth-0-7f584587cf-8jfwk:/# date
Thu Jan 16 11:57:22 UTC 2020
root@sawtooth-0-7f584587cf-8jfwk:/# exit
exit
command terminated with exit code 130

连接到锯齿波-1

PS C:\Users\winuser> kubectl exec -it $(kubectl get pods --no-headers -o custom-columns=":metadata.name" | findstr -i sawtooth-1) --container sawtooth-shell -- bash
root@sawtooth-1-6ccd4494-kq24n:/# date
Thu Jan 16 12:17:33 UTC 2020

相关问题