10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Kubernetes 1.18 Flag --replicas has been deprecated, has no effect and will be removed in the future

Posted at

kubectl run の挙動が1.18から変更になった

Kubernetesで用いるマニフェストをワンライナーで生成したい場面にて、このエラーに遭遇したのでまとめる。
偉大な先人によってすでに懸念が示されているが、kubernetes 1.18よりkubectl runコマンドがPods作成のみのコマンドとなったため、今までkubectl runコマンドにてdeployment, job, cronjobなどを生成していた人は読み替えが必要になる。

参考: 「Kubernetes 1.18: SIG-CLI の変更内容」
https://qiita.com/superbrothers/items/eef275853b0c2d14e95c

❯ kubectl run nginx --image=nginx --replicas=2
Flag --replicas has been deprecated, has no effect and will be removed in the future.

kubectl runはどんな挙動をするようになったか

環境

Kubernetes 1.18.2
kind v0.8.1
macOS Catalina

❯ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-16T23:35:15Z", GoVersion:"go1.14.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-04-30T20:19:45Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

Deploymentを作ろうとしても、podができる(失敗例)

❯ kubectl run nginx --image=nginx --replicas=2
Flag --replicas has been deprecated, has no effect and will be removed in the future.
pod/nginx created

Jobを作ろうとしても、podができる(失敗例)

❯ kubectl run my-job --image=busybox  --restart=OnFailure -- date
pod/my-job created

CronJobを作ろうとしても、Podができる(失敗例)

❯ kubectl run test-job --image=busybox --restart=OnFailure --schedule="* * * * *" -- date
Flag --schedule has been deprecated, has no effect and will be removed in the future.
pod/test-job created

どうしたらよいのか

Deploymentを作りたいとき

残念ながらreplicasオプションがないため、Deployment作成後にscaleする感じになる

kubectl create deployment nginx --image=nginx
kubectl scale deployment nginx --replicas=2

Jobを作りたいとき

kubectl create job my-job --image=busybox -- date
job.batch/my-job created

CronJobを作りたいとき

kubectl create cronjob test-job --image=busybox --schedule="*/1 * * * *" -- date
cronjob.batch/test-job created

kubectl create を使用する場合のメモ

kubectl create <リソース名>とすることで、コマンドの使用例が出てくるので呪文のようなkubectl runコマンドを用いてyamlを生成する必要がなくなった 嬉しい!

下記はDeploymentの例

❯ kubectl create deploy -h
Create a deployment with the specified name.

Aliases:
deployment, deploy

Examples:
  # Create a new deployment named my-dep that runs the busybox image.
  kubectl create deployment my-dep --image=busybox
10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?