第 6 章 OpenShift CLI 命令参考
本参考提供了 OpenShift CLI (oc) 命令的描述和示例命令。您必须具有 cluster-admin 或同等权限才能使用这些命令。
运行 oc adm -h 以列出所有管理员命令或运行 oc <command> --help 获取特定命令的更多详情。
重要
使用 oc <command> --help 列出所有 oc 命令的详情。并非所有 oc 命令都适用于使用 MicroShift 的红帽构建。
6.1. oc command list for Red Hat build of MicroShift 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
以下列出了几个 oc 命令示例,可用于管理、部署和观察红帽构建的 MicroShift 节点。
6.1.1. oc apply 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
通过文件名或 stdin 将配置应用到资源
用法示例
# Apply the configuration in pod.json to a pod
oc apply -f ./pod.json
# Apply resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
oc apply -k dir/
# Apply the JSON passed into stdin to a pod
cat pod.json | oc apply -f -
# Apply the configuration from all files that end with '.json' - i.e. expand wildcard characters in file names
oc apply -f '*.json'
# Note: --prune is still in Alpha
# Apply the configuration in manifest.yaml that matches label app=nginx and delete all other resources that are not in the file and match label app=nginx
oc apply --prune -f manifest.yaml -l app=nginx
# Apply the configuration in manifest.yaml and delete all the other config maps that are not in the file
oc apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap
6.1.2. oc delete 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
通过文件名、stdin、资源和名称或者资源和标签选择器删除资源
用法示例
# Delete a pod using the type and name specified in pod.json
oc delete -f ./pod.json
# Delete resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
oc delete -k dir
# Delete resources from all files that end with '.json' - i.e. expand wildcard characters in file names
oc delete -f '*.json'
# Delete a pod based on the type and name in the JSON passed into stdin
cat pod.json | oc delete -f -
# Delete pods and services with same names "baz" and "foo"
oc delete pod,service baz foo
# Delete pods and services with label name=myLabel
oc delete pods,services -l name=myLabel
# Delete a pod with minimal delay
oc delete pod foo --now
# Force delete a pod on a dead node
oc delete pod foo --force
# Delete all pods
oc delete pods --all
6.1.3. oc get 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
显示一个或多个资源
用法示例
# List all pods in ps output format
oc get pods
# List all pods in ps output format with more information (such as node name)
oc get pods -o wide
# List a single replication controller with specified NAME in ps output format
oc get replicationcontroller web
# List deployments in JSON output format, in the "v1" version of the "apps" API group
oc get deployments.v1.apps -o json
# List a single pod in JSON output format
oc get -o json pod web-pod-13je7
# List a pod identified by type and name specified in "pod.yaml" in JSON output format
oc get -f pod.yaml -o json
# List resources from a directory with kustomization.yaml - e.g. dir/kustomization.
oc get -k dir/
# Return only the phase value of the specified pod
oc get -o template pod/web-pod-13je7 --template={{.status.phase}}
# List resource information in custom columns
oc get pod test-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image
# List all replication controllers and services together in ps output format
oc get rc,services
# List one or more resources by their type and names
oc get rc/web service/frontend pods/web-pod-13je7
# List status subresource for a single pod.
oc get pod web-pod-13je7 --subresource status