- Usage:
- Available Commands:
- Options:
- Examples:
- Create a pod using the data in pod.yaml.
kubectl create -f ./pod.yaml
#创建一个命名空间
kubectl create namespace NAME - 创建资源时使用命令选项 -n 指定命名空间
kubectl create -f kubia-manual.yaml -n custom-namespace
- Create a new secret named my-secret with keys for each file in folder bar
kubectl create secret generic my-secret --from-file=path/to/bar
- Create a new secret named my-secret using a combination of a file and a literal
kubectl create secret generic my-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret
- 为本地仓库鉴权创建docker-registry Secret (注意docker-server要加端口)
kubectl create secret docker-registry myregistrysecret —docker-username=user —docker-password=password —docker-server=10.0.0.10:5000 —docker-email=my.email@163.com - Create a new configmap named my-config based on folder bar
kubectl create configmap my-config --from-file=path/to/bar/
- Create a new configmap named my-config with specified keys instead of file basenames on disk
kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
- Create a new configmap named my-config with key1=config1 and key2=config2
kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2
Create a resource from a file or from stdin. JSON and YAML formats are accepted.
Usage:
kubectl create -f FILENAME
Available Commands:
namespace 创建一个指定名称的 namespace
configmap 从本地 file, directory 或者 literal value 创建一个 configmap
secret Create a secret using specified subcommand
Options:
-f, —filename=[]: Filename, directory, or URL to files to use to create the resource
-o, —output=’’: Output format. One of: json|yaml|name等等
-l, —selector=’’: (label selector),Selector (label query) to filter on
—record=false: Record current kubectl command in the resource annotation. If set to false, do
not record the ommand. If set to true, record the command. If not set, default to updating the
existing annotation value only if one already exists.
Examples:
Create a pod using the data in pod.yaml.
kubectl create -f ./pod.yaml
#创建一个命名空间
kubectl create namespace NAME
创建资源时使用命令选项 -n 指定命名空间
kubectl create -f kubia-manual.yaml -n custom-namespace
Create a secret using specified subcommand.
Available Commands:
docker-registry Create a secret for use with a Docker registry
generic Create a secret from a local file, directory or literal value
tls Create a TLS secret
Usage:
kubectl create secret tls NAME —cert=path/to/cert/file —key=path/to/key/file
kubectl create secret docker-registry NAME —docker-username=user —docker-password=password —docker-email=email
kubectl create secret generic NAME [—type=string] [—from-file=[key=]source] [—from-literal=key1=value1]
—from-file=[]: Key files can be specified using their file path, in which case a default name will be given to
them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will
iterate each named file in the directory that is a valid secret key.
—from-literal=[]: Specify a key and literal value to insert in secret (i.e. mykey=somevalue)
Examples:
# Create a new TLS secret named tls-secret with the given key pair:kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key
Create a new secret named my-secret with keys for each file in folder bar
kubectl create secret generic my-secret --from-file=path/to/bar
Create a new secret named my-secret using a combination of a file and a literal
kubectl create secret generic my-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret
为本地仓库鉴权创建docker-registry Secret (注意docker-server要加端口)
kubectl create secret docker-registry myregistrysecret —docker-username=user —docker-password=password —docker-server=10.0.0.10:5000 —docker-email=my.email@163.com
Create a configmap based on a file, directory, or specified literal value.
Usage:
kubectl create configmap NAME [—from-file=[key=]source] [—from-literal=key1=value1]
--from-file=[]: Key file can be specified using its file path, in which case file basename will be used as configmap key, or optionally with a key and file path, in which case the given key will be used. Specifying a directory will iterate each named file in the directory whose basename is a valid configmap key.<br /> --from-literal=[]: Specify a key and literal value to insert in configmap (i.e. mykey=somevalue)