📅  最后修改于: 2023-12-03 15:17:10.893000             🧑  作者: Mango
Kubernetes是一款支持容器化技术的自动化部署系统,旨在简化容器化应用程序的部署、扩展和管理。其中,kubernetes get -o yaml
是一条命令行指令,在Shell-Bash环境中使用,它可以帮助开发者获得Kubernetes API对象的详细信息,以一份YAML文件格式的形式返回。
kubectl get [-f filename] [(-o|--output=)json|yaml|wide|custom-columns=...] [--no-headers] [-w|--watch] [-a|--all-namespaces] [-A|--all]
-f
--filename
:使用指定的文件名或标准输入获取Kubernetes API的对象-o
--output
:输出格式json
:以JSON格式显示数据yaml
:以YAML格式显示数据wide
:以更加详细的方式显示数据custom-columns
:自定义列显示格式--no-headers
:在输出结果中省略表头-w
--watch
:持续观察状态变化-a
--all-namespaces
:列出所有的命名空间-A
--all
:列出所有的所有资源以下范例将获取 Kubernetes Pod 的详细信息,并将结果以 YAML 格式返回:
kubectl get pods my-pod -o yaml
返回的结果将如下所示:
```yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubernetes.io/psp: eks.privileged
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"app":"my-app"},"name":"my-pod","namespace":"default"},"spec":{"containers":[{"image":"nginx","name":"my-container","ports":[{"containerPort":80,"name":"http","protocol":"TCP"}]}]}}
creationTimestamp: "2021-08-02T12:46:05Z"
labels:
app: my-app
name: my-pod
namespace: default
resourceVersion: "4446547"
uid: 6a8c75cf-ad00-48e5-b5d5-b40fc8e5fc16
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: my-container
ports:
- containerPort: 80
name: http
protocol: TCP
resources:
limits:
cpu: "2"
memory: 2Gi
requests:
cpu: "1"
memory: 1Gi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: my-token-hnvhb
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: ip-10-0-1-197.us-west-2.compute.internal
preemptionPolicy: PreemptLowerPriority
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: false
runAsUser: 1000
serviceAccount: my-token-hnvhb
serviceAccountName: my-token-hnvhb
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 50
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 50
volumes:
- name: my-token-hnvhb
secret:
defaultMode: 420
secretName: my-token-hnvhb
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2021-08-02T12:46:05Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2021-08-02T12:46:29Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2021-08-02T12:46:29Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2021-08-02T12:46:05Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://62e2caf6cf089f6bf1aab709bbe8f61c3f6eba56ab9d05e5865b5a5ed5a5a5c5
image: nginx
imageID: docker-pullable://nginx@sha256:e7d00cf1e05d7f6b2d4ea1284bd4e45d1badd9dedad75762b1fbe15b3e139ee7
name: my-container
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2021-08-02T12:46:28Z"
hostIP: 10.0.1.197
phase: Running
podIP: 10.0.1.80
podIPs:
- ip: 10.0.1.80
qosClass: BestEffort
startTime: "2021-08-02T12:46:05Z"
kubernetes get -o yaml
向开发者提供了获取 Kubernetes API 对象详细信息的途径,同时将信息以 YAML 格式返回。使用该指令可以使开发者更加清晰地了解 Kubernetes 应用程序的表现和运作情况。