Awk 来自服务器的错误(未找到):pods"$(kubectl“未找到

Awk 来自服务器的错误(未找到):pods"$(kubectl“未找到,awk,kubernetes,hyperledger,minikube,hyperledger-sawtooth,Awk,Kubernetes,Hyperledger,Minikube,Hyperledger Sawtooth,在minikube hyper-v机器中,我使用 现在,当我检查running Pod时,它似乎有一些默认的pod,但在尝试连接kubernetes外壳容器时 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

在minikube hyper-v机器中,我使用

现在,当我检查running Pod时,它似乎有一些默认的pod,但在尝试连接kubernetes外壳容器时

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>
C:\Users\Debo>kubectl-get——所有名称空间
必须指定要获取的资源类型。请使用“kubectl api资源”查看受支持资源的完整列表。
错误:未指定所需的资源。
使用“kubectl解释”详细描述该资源(例如kubectl解释吊舱)。
有关帮助和示例,请参见“kubectl get-h”
C:\Users\Debo>kubectl获取pods——所有名称空间
名称空间名称就绪状态重新启动
默认锯齿-0-65d547498c-mfrsb 7/7运行120m
kube系统coredns-6955765f44-b684l 1/1运行0 122m
kube系统coredns-6955765f44-tc4vg 1/1运行0 122m
kube系统etcd minikube 1/1运行0 121m
kube系统kube插件管理器minikube 1/1运行0 121m
kube系统kube apiserver minikube 1/1运行0 121m
kube系统kube控制器管理器minikube 1/1运行0 121m
kube系统kube-proxy-t7nhs 1/1运行0 122m
kube系统kube调度程序minikube 1/1运行0 121m
kube系统存储供应器1/1运行0 122m
kubernetes仪表板仪表板-metrics-scraper-7b64584c5c-b8t7s 1/1运行0 122m
kubernetes仪表板kubernetes-dashboard-79d9cd965-pn94z 1/1运行0 122m
C:\Users\Debo>kubectl获取吊舱
名称就绪状态重新启动
锯齿形-0-65d547498c-mfrsb 7/7运行120m
C:\Users\Debo>kubectl exec-it$(kubectl get pods | awk“/sawtooth-0/{print$1}”)--容器锯齿壳--bash
awk:/sawtooth-0/{print$1})
awk:^语法错误
错误计数:1
服务器错误(未找到):未找到播客“$(kubectl)”
C:\Users\Debo>

如果我了解您的用例,您将尝试从命名空间中的给定pod列表中筛选sawtooth-0 pod,然后打开一个交互式会话,指向其中运行的容器,您知道容器名称。

为了解决上面的问题,我使用了附带的sawtooth配置文件,并在几个虚拟吊舱旁边启动了sawtooth-0和sawtooth-1的两个实例,然后在windows power shell上使用此命令过滤并连接到sawtooth-0吊舱上的容器

假设您需要在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

用单引号尝试
awk
命令-
awk'/sawtooth-0/{print$1}'
或do
awk/{print\$1}'
“`C:\Users\Debo>kubectl exec-it$(kubectl get pods | awk'/sawtooth-0/{print$1}')--容器锯齿壳--bash awk:'/sawtooth-0/awk:^invalid char in服务器的表达式错误(未找到):pods“$(kubectl”未找到C:\Users\Debo>kubectl exec-it$(kubectl get pods | awk”/sawtooth-0/{print\$1}”)--容器锯齿壳--bash awk:/sawtooth-0/{print\$1}awk:^来自服务器的反斜杠非最后一行字符错误(未找到):pods“$(kubectl”找不到“``看起来像Windows命令提示符,但Unix Bourne shell语法不起作用。您实际使用的shell是什么,它是否支持Bourne shell
$(命令)
替换语法?(<代码> Kubbtl获取POD- o名称<代码> >可能比“代码> AWK< /Cult>调用更健壮;还考虑由标签<代码> Cubbtl获取POD -L APP =锯齿< /代码>或类似,以避免需要<代码> AWK <代码> GRP /<代码> SED步骤)。你到底想实现什么?Kubernetes有许多内置命令。如果你想从sawtooth pod连接到特定的容器,你可以使用
kubectl exec-ti sawtooth-0-65d547498c-mfrsb-c/bin/bash
这只是一个离题-看起来kubectl exec需要容器名(不管我们是否指定).难道没有办法只连接吊舱(而不是容器)吗?