大网数据广告活动
服务器运维问答

What's is the purpose of a trailing '-' in a Kubernetes apply -f -

· 52CE 我爱测

I was passed the following, which does a dry run of the creation of a kubernetes secret from an appsettings.json file, which is then piped to a kubernetes apply . I think that the -f will take the filename of the --dry-run create…

问题原文

原帖链接 · Chris Halcrow · CC BY-SA 4.0

I was passed the following, which does a dry run of the creation of a kubernetes secret from an appsettings.json file, which is then piped to a kubernetes apply. I think that the -f will take the filename of the --dry-run created secret and use that when applying the secret, but I'm wondering if the trailing - has any significance or if it's just a typo?

kubectl create secret generic test --from-file=appsettings.json --dry-run -oyaml | kubectl apply -f -

已采纳解答

原帖链接 · mario · CC BY-SA 4.0

The - character can be understood as a placeholder for the output of the command which is piped ( using | character ). By using it, we instruct very specifically the subsequent command ( to which the output is piped ), where the standard output of the first command ( it's execution result ) should be placed, in other words how it should be taken or parsed.

So rather than piping the result of:

kubectl create secret generic test --from-file=appsettings.json --dry-run -oyaml

(which happens to be a yaml manifest)

directly to:

kubectl apply -f

which doesn't know what to do with such input (as it expects a file after -f flag), we indicate very precisely where it fits:

                
kubectl apply -f -

In this case, we instruct kubectl apply command that the piped output from the previous command should be taken instead of a file, which is expected after providing -f flag.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-11-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。