4、Kubernetes 资源清单

╰半橙微兮° 2023-07-07 11:21 131阅读 0赞

资源清单格式

  1. apiVersion: group/apiversion # 如果没有给定 group 名称,那么默认为 core,
  2. 可以使用 kubectl api-versions # 获取当前 k8s 版本上所有的 apiVersion 版本信息( 每个版本可能不同 )
  3. kind: #资源类别
  4. metadata #资源元数据
  5. name
  6. namespace
  7. lables
  8. annotations # 主要目的是方便用户阅读查找
  9. spec: # 期望的状态(disired state)
  10. status:# 当前状态,本字段有 Kubernetes 自身维护,用户不能去定义

资源清单的常用命令

获取 apiversion 版本信息

  1. kubectl api-versions

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d0bDE5OTI_size_16_color_FFFFFF_t_70

获取资源的 apiVersion 版本信息

  1. kubectl explain pod

20200223001859429.png

  1. kubect explain ingress

20200223095224410.png

字段配置格式

  1. apiVersion <string> #表示字符串类型
  2. metadata <Object> #表示需要嵌套多层字段
  3. labels <map[string]string> #表示由k:v组成的映射
  4. finalizers <[]string> #表示字串列表
  5. ownerReferences <[]Object> #表示对象列表
  6. hostPID <boolean> #布尔类型
  7. priority <integer> #整型
  8. name <string> -required- #如果类型后面接 -required-,表示为必填字段

通过定义清单文件创建 Pod

定义pod.yaml

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: pod-demo
  5. namespace: default
  6. labels:
  7. app: myapp
  8. version: v1
  9. spec:
  10. containers:
  11. - name: myapp-1
  12. image: wangyanglinux/myapp:v1
  13. - name: busybox-1
  14. image: busybox:latest
  15. command:
  16. - "/bin/sh"
  17. - "-c"
  18. - "sleep 3600"

根据yaml文件进行启动容器

  1. kubectl apply -f pod.yaml

查看容器报错的方法:

查看pod容器的详细信息,包括容器的状态信息等

  1. kubectl describe pod pod-demo

查看容器log日志

  1. kubectl logs pod-demo -c myapp-1

修改service,暴露外网端口

  1. # Please edit the object below. Lines beginning with a '#' will be ignored,
  2. # and an empty file will abort the edit. If an error occurs while saving this file will be
  3. # reopened with the relevant failures.
  4. #
  5. apiVersion: v1
  6. kind: Service
  7. metadata:
  8. creationTimestamp: "2020-02-22T12:45:10Z"
  9. labels:
  10. run: nginx-linux
  11. name: nginx-linux
  12. namespace: default
  13. resourceVersion: "166951"
  14. selfLink: /api/v1/namespaces/default/services/nginx-linux
  15. uid: e85b8894-c0f2-4c9f-81cd-1361505ccb21
  16. spec:
  17. clusterIP: 10.110.158.235
  18. externalTrafficPolicy: Cluster
  19. ports:
  20. - nodePort: 30357
  21. port: 30000
  22. protocol: TCP
  23. targetPort: 80
  24. selector:
  25. run: nginx-linux
  26. sessionAffinity: None
  27. type: NodePort
  28. status:
  29. loadBalancer: {}

发表评论

表情:
评论列表 (有 0 条评论,131人围观)

还没有评论,来说两句吧...

相关阅读

    相关 kubernetes--资源清单

    ⒈资源含义   k8s中所有的内容都被抽象为资源,资源实例化之后,叫做对象。 ⒉资源分类   名称空间级别   仅在此名称空间下生效,k8s的系统组件是默认放在kube