kubernetes查看现有pod的YAML描述文件

命令: kubectl get pod [pod名字] -o yaml

kubectl get pod httpd-gv4bl -o yaml

yaml描述文件结果

 
apiVersion: v1   --YAML描述文件所使用的Kubernetes API版本
kind: Pod        --Kubernetes 对象资源 
metadata:        --pod元数据(名称、标签和注解)
  creationTimestamp: 2019-09-03T06:05:16Z
  generateName: httpd-
  labels:
    run: httpd
  name: httpd-gv4bl
  namespace: default
  ownerReferences:
  - apiVersion: v1
    blockOwnerDeletion: true
    controller: true
    kind: ReplicationController
    name: httpd
    uid: 049ce8c5-035b-4422-a3b0-40e814d5c820
  resourceVersion: "1640"
  selfLink: /api/v1/namespaces/default/pods/httpd-gv4bl
  uid: b032b3bd-b42f-476a-b5fa-93121169fc7b
spec:           --pod规格/内容(pod的容器列表、volume)
  containers:
  - image: httpd
    imagePullPolicy: Always
    name: httpd
    ports:
    - containerPort: 80
      protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-mrn2n
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: minikube
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-mrn2n
    secret:
      defaultMode: 420
      secretName: default-token-mrn2n
status:             --pod及其内部容器的详细状态
  conditions:
  - lastProbeTime: null
    lastTransitionTime: 2019-09-03T06:05:16Z
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: 2019-09-03T06:07:54Z
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: 2019-09-03T06:07:54Z
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: 2019-09-03T06:05:16Z
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://0ed3b5ef7bf2de481f26d23b9a431094412443db004ea04c6e57d9157baf8e1b
    image: httpd:latest
    imageID: docker-pullable://httpd@sha256:98caed3e3a90ed9db8d25dcbb98eebe0ce56358a9dbbc940d7eb66a8e2b88252
    lastState: {}
    name: httpd
    ready: true
    restartCount: 0
    state:
      running:
        startedAt: 2019-09-03T06:07:53Z
  hostIP: 192.168.122.91
  phase: Running
  podIP: 172.17.0.4
  qosClass: BestEffort
  startTime: 2019-09-03T06:05:16Z

参考

https://blog.csdn.net/xufengduo/article/details/100518814

### Kubernetes Pod YAML 配置示例 以下是基于提供的引用内容以及专业知识所整理的一个完整的 Kubernetes Pod YAML 配置示例: #### 基础配置 Kubernetes 使用 YAML 文件来定义资源对象,例如 Pods、Deployments 和 Services 等。下面是一个简单的 Pod 定义示例[^3]。 ```yaml apiVersion: v1 kind: Pod metadata: name: example-pod namespace: default spec: containers: - name: example-container image: nginx:latest ports: - containerPort: 80 ``` 此配置创建了一个名为 `example-pod` 的 Pod,在默认命名空间下运行 Nginx 容器,并暴露端口 80。 #### 存活性探测 (Liveness Probe) 实战案例 根据引用中的描述[^5],以下是一个更复杂的 Pod 配置实例,展示了如何设置存活性探测(Liveness Probe)。这个例子模拟了容器健康状态的变化过程。 ```yaml apiVersion: v1 kind: Pod metadata: name: liveness-exec namespace: default spec: containers: - name: liveness image: busybox args: - /bin/sh - -c - touch /tmp/healthy; sleep 60; rm -rf /tmp/healthy; sleep 600 livenessProbe: exec: command: - test - -e - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5 ``` 在此配置中: - 容器启动时会创建 `/tmp/healthy` 文件,并在 60 秒后删除它。 - Liveness 探测每 5 秒执行一次,检查是否存在 `/tmp/healthy` 文件。如果文件不存在,则认为容器不健康并重启容器。 #### 查看和更新 Pod 资源 可以通过以下命令查看 Pod 的详细状态或应用新的资源配置[^1][^2]: - **查看 PodYAML 配置**: ```bash kubectl get pod <pod_name> -o yaml ``` - **更新现有资源**: ```bash kubectl apply -f <path_to_yaml_file> ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值