【发布时间】:2021-04-19 02:49:52
【问题描述】:
在Kubernetes: Up and Running, 2nd Edition的第67页,作者使用以下命令创建Deployment:
kubectl run alpaca-prod \
--image=gcr.io/kuar-demo/kuard-amd64:blue \
--replicas=2 \
--labels="ver=1,app=alpaca,env=prod"
但是,kubectl 1.19+ 不推荐使用此命令,它现在创建一个 pod:
$ kubectl run alpaca-prod \
--image=gcr.io/kuar-demo/kuard-amd64:blue \
--replicas=2 \
--labels="ver=1,app=alpaca,env=prod"
Flag --replicas has been deprecated, has no effect and will be removed in the future.
pod/alpaca-prod created
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-21T01:11:42Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
有没有办法使用kubectl run 来创建具有副本的部署和带有kubectl 1.19+ 的自定义标签?
【问题讨论】:
-
我建议你使用
kubectl apply和 yaml 资源。您可以在此处定义部署并稍后对其进行更新。因为这就是你最终在实际工作中做这件事的方式。 -
kubectl create deployment alpaca-prod --image=gcr.io/kuar-demo/kuard-amd64:blue --replicas=2应该可以。但是你需要在创建后添加标签。 -
...并将 YAML 文件检查到源代码管理中,这样您就可以记录部署的内容,并且可以稍后重新创建它(可能在不同的环境中)。
标签: kubernetes kubectl