赞
踩
kubectl explain pods
定义了此对象表示的版本化模式。
服务器应将已识别的模式转换为最新的内部值,并可能拒绝无法识别的值。
[root@master1 ~]# kubectl api-versions admissionregistration.k8s.io/v1 admissionregistration.k8s.io/v1beta1 apiextensions.k8s.io/v1 apiextensions.k8s.io/v1beta1 apiregistration.k8s.io/v1 apiregistration.k8s.io/v1beta1 apps/v1 authentication.k8s.io/v1 authentication.k8s.io/v1beta1 authorization.k8s.io/v1 authorization.k8s.io/v1beta1 autoscaling/v1 autoscaling/v2beta1 autoscaling/v2beta2 batch/v1 batch/v1beta1 certificates.k8s.io/v1beta1 coordination.k8s.io/v1 coordination.k8s.io/v1beta1 crd.projectcalico.org/v1 discovery.k8s.io/v1beta1 events.k8s.io/v1beta1 extensions/v1beta1 metrics.k8s.io/v1beta1 networking.k8s.io/v1 networking.k8s.io/v1beta1 node.k8s.io/v1beta1 policy/v1beta1 rbac.authorization.k8s.io/v1 rbac.authorization.k8s.io/v1beta1 scheduling.k8s.io/v1 scheduling.k8s.io/v1beta1 storage.k8s.io/v1 storage.k8s.io/v1beta1 v1
此对象的资源类型,如deployment、statefulset、pod、service、ingress。
对象的元数据
指定容器的所需行为
# 查看 pods 需要哪些字段
kubectl explain pods
# 查看 apiVersion 需要哪些字段
kubectl explain pods.apiVersion
# 查看 kind 需要哪些字段
kubectl explain pods.kind
# 查看 spec 需要哪些字段
kubectl explain pods.metadata
# 查看 spec 需要哪些字段
kubectl explain pods.spec
vim /root/k8s/test/pod.yaml
内容
apiVersion: v1
kind: Pod
metadata:
name: web
namespace: default
labels:
web1: tomcat
spec:
containers:
- name: tomcat1
image: tomcat:8.5-jre8-alpine
imagePullPolicy: IfNotPresent
kubectl apply -f /root/k8s/test/pod.yaml
kubectl get pods
kubectl describe pods web
内容
[root@master1 test]# kubectl describe pods web Name: web Namespace: default Priority: 0 Node: node1/192.168.187.155 Start Time: Sun, 10 Apr 2022 09:44:48 +0800 Labels: web1=tomcat Annotations: cni.projectcalico.org/podIP: 10.244.1.41/32 Status: Running IP: 10.244.1.41 IPs: IP: 10.244.1.41 Containers: tomcat1: Container ID: docker://a553044eeddcb7333a4f62a522dfeb1cd33878f80790d782df91e165490e4635 Image: tomcat:8.5-jre8-alpine Image ID: docker-pullable://tomcat@sha256:04feaf74f8bb54b43ea136b150bbc7b58e8a3062aead67ab871f2dbbd5dac5d1 Port: <none> Host Port: <none> State: Running Started: Sun, 10 Apr 2022 09:44:50 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-8z75k (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-8z75k: Type: Secret (a volume populated by a Secret) SecretName: default-token-8z75k Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 48s default-scheduler Successfully assigned default/web to node1 Normal Pulled 47s kubelet Container image "tomcat:8.5-jre8-alpine" already present on machine Normal Created 47s kubelet Created container tomcat1 Normal Started 47s kubelet Started container tomcat1 [root@master1 test]#
kubectl delete -f/root/k8s/test/pod.yaml
kubectl get pods -o wide
kubectl logs web
kubectl logs -c tomcat1 web
kubectl exec -it web -- /bin/bash
kubectl exec -it web -c tomcat1 -- /bin/bash
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。