kubectl 命令详解(二):create

一、命令作用

通过配置文件名或stdin创建一个集群资源对象。

支持JSON和YAML格式的文件。

语法如下:

kubectl create -f FILENAME

二、命令选项

在安装有k8s的机器上输入如下命令:

sudo kubectl create --help
或
kubectl create --help

根据权限选择是否需要 sudo。

可以看到类似如下输出:

Create a resource from a file or from stdin.

 JSON and YAML formats are accepted.

Examples:
  # Create a pod using the data in pod.json.
  kubectl create -f ./pod.json

  # Create a pod based on the JSON passed into stdin.
  cat pod.json | kubectl create -f -

  # Edit the data in docker-registry.yaml in JSON then create the resource using the edited data.
  kubectl create -f docker-registry.yaml --edit -o json

该命令可用命令如下:

Available Commands:
  clusterrole         Create a ClusterRole.
  clusterrolebinding  为一个指定的 ClusterRole 创建一个 ClusterRoleBinding
  configmap           从本地 file, directory 或者 literal value 创建一个 configmap
  cronjob             Create a cronjob with the specified name.
  deployment          Create a deployment with the specified name.
  ingress             Create an ingress with the specified name.
  job                 Create a job with the specified name.
  namespace           创建一个指定名称的 namespace
  poddisruptionbudget 创建一个指定名称的 pod disruption budget.
  priorityclass       Create a priorityclass with the specified name.
  quota               创建一个指定名称的 quota.
  role                Create a role with single rule.
  rolebinding         为一个指定的 Role 或者 ClusterRole创建一个 RoleBinding
  secret              使用指定的 subcommand 创建一个 secret
  service             使用指定的 subcommand 创建一个 service.
  serviceaccount      创建一个指定名称的 service account

有如下选项:

Options:
      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
      --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
sent, without sending it. If server strategy, submit server-side request without persisting the resource.
      --edit=false: Edit the API resource before creating
      --field-manager='kubectl-create': Name of the manager used to track field ownership.
  -f, --filename=[]: Filename, directory, or URL to files to use to create the resource
  -k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
  -o, --output='': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.
      --raw='': Raw URI to POST to the server.  Uses the transport specified by the kubeconfig file.
      --record=false: Record current kubectl command in the resource annotation. If set to false, do not record the
command. If set to true, record the command. If not set, default to updating the existing annotation value only if one
already exists.
  -R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage
related manifests organized within the same directory.
      --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
      --validate=true: If true, use a schema to validate the input before sending it
      --windows-line-endings=false: Only relevant if --edit=true. Defaults to the line ending native to your platform.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
kubectl是Kubernetes的命令行工具,用于与Kubernetes集群进行交互和管理。下面是kubectl的一些常用命令及其详解: 1. kubectl get:用于获取资源的信息。例如,使用kubectl get pods可以获取当前集群中所有的Pod信息。 2. kubectl create:用于创建资源。例如,使用kubectl create deployment可以创建一个新的Deployment。 3. kubectl apply:用于应用配置文件或更新资源。例如,使用kubectl apply -f deployment.yaml可以应用一个Deployment的配置文件。 4. kubectl describe:用于查看资源的详细信息。例如,使用kubectl describe pod my-pod可以查看名为my-pod的Pod的详细信息。 5. kubectl delete:用于删除资源。例如,使用kubectl delete pod my-pod可以删除名为my-pod的Pod。 6. kubectl exec:用于在容器内执行命令。例如,使用kubectl exec my-pod -- ls可以在名为my-pod的Pod中执行ls命令。 7. kubectl logs:用于查看容器的日志。例如,使用kubectl logs my-pod可以查看名为my-pod的Pod中容器的日志。 8. kubectl port-forward:用于将本地端口与Pod或Service的端口进行转发。例如,使用kubectl port-forward my-pod 8080:80可以将本地的8080端口与名为my-pod的Pod中的80端口进行转发。 9. kubectl scale:用于调整资源的副本数。例如,使用kubectl scale deployment/my-deployment --replicas=3可以将名为my-deployment的Deployment的副本数调整为3。 10. kubectl rollout:用于管理资源的滚动更新。例如,使用kubectl rollout restart deployment/my-deployment可以重新启动名为my-deployment的Deployment。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值