Kubernetes resource configuration list commonly used resources

Resource: Object

workload: 
    Pod
    ReplicaSet
    Deployment
    StatefulSet
    DaemonSet
    job
    Cronjob
    ...
服务发现及负载均衡:
    Service、ingress,...
配置与存储:
    Volume
    CSI
    配置中心:ConfigMap
    密钥:Secret

The first-level fields of the resource configuration list:

apiVersion(格式:group/version)  通过:kubectl api-versions获取
'kind':定义资源类型(如:Pod,Service,...)
'metadata':元数据 
    name:容器名称,同一资源类别必须是唯一的
    namespace:名称空间
    labels:标签
    annotions:资源注解
'spac':用户所期望的状态 
    contaioners
    ports
    hostNetwork
    nodeSelector
    restartPolicy 
'status'(只读):容器运行的当前状态

Built-in help documentation

kubectl explain RESOURCE
需要看定义RESOURCE下一级资源,

]# kubectl explain pod
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources

   kind <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds

   metadata     <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata

   spec <Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

   status       <Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

Run a simple self-service pod

apiVersion: v1
kind: Pod
metadata:
   name: myapp-dome
   namespace: default
   labels: #labels是Map类型的资源,属于Json数组,可以”{key:vlue,key:vlue},也可以是换行缩紧格式
      apps: myapp
      tier: qianduan
spec:
   containers: #containers是Json对象列表资源,书写格式换行以“-”开头
   - name: myapp
     image: ikubernetes/myapp:v1

Common fields of spec

==containers== define containers

containers:#常用下级字段
- name:#定义容器名称
  image:#定义镜像
  imagePullPolicy: # 定义镜像下载策略,有Always、Never、IfNotPresent
        Always:总是按照地址下载镜像
        Never:不下载镜像,需要手动下载镜像
        IfNotPresent:如果本地有镜像就使用本地的镜像,如果本地没有就按照地址下载镜像
    "注意:如果镜像标签是latest,没有定义策略,那么默认就是Always"

apiVersion:v1
kind:Pod
metadata:
    name: myapp
    ....
spec:
    "containers:" #对象列表资源 下级字段"name" -required- 必填字段
    - name: nginx 
      image: nginx:latest

==containers.ports== Define container exposure ports

port #字段常用下级字段
- name: #定义端口名称
  containerPort:<nmber> #容器端口号
  portocol:#定义协议类型,TCP、UDP或者 SCTP,默认是TCP;

apiVersion:v1
kind:Pod
metadata:
    name: myapp
    ....
spec:
    containers: 
    - name: nginx
      image:nginx: latest
      "ports:
      - name: http
        containerPort: 80
        portocol: tcp"

==nodeselector== Define the node selector to schedule to the corresponding node node according to the label value

 nodeSelector <map[string]string>

 例如:
    apiVersion:V1
    kind:Pod
    metadata;

livenessProbe liveness status check

探测方式:
    命令探测方式:exec
              command
    请求业务:httpGet
              port
              path
    tcp套接字:tcpSocket
              port
常用字段:
       "livenessProbe:
        exec: #命令探测方式
          command: ["/bin/sh","-c","test -e /usr/share/nginx/html/index.html"]
        initialDelaySeconds: 3
        timeoutSeconds: 2
        failureThreshold: 3"

command 用法示例:
apiVersion: v1
kind: Pod
metadata:
    name: liveness-pod
    namespace: default
    labels:
       version: v0.1
spec:
    containers:
    - name: liveness
      image: ikubernetes/myapp:v1
      ports:
      - name: http
        containerPort: 80
      "livenessProbe:
        exec: 
          command: ["/bin/sh","-c","test -e /usr/share/nginx/html/index.html"]
        initialDelaySeconds: 3
        timeoutSeconds: 2
        failureThreshold: 3"
    restartPolicy: Always

httpGet用法示例:
apiVersion: v1
kind: Pod
metadata:
    name: liveness-httpget-pod
    namespace: default
    labels:
       version: v0.1
spec:
    containers:
    - name: liveness-httpget-containter
      image: ikubernetes/myapp:v1
      ports:
      - name: http
        containerPort: 80
      livenessProbe:
        "httpGet:
           path: http://liveness-httpget-containter/index.html
           port: http"
        initialDelaySeconds: 3 #启动多少秒开始探测
        timeoutSeconds: 2 #超时时间
        failureThreshold: 3 #失败次数
    restartPolicy: Always

tcpSocker 用法:
    apiVersion: v1
    kind: Pod
    metadata:
        name: liveness-tcpsocket-pod
        namespace: default
        labels:
           version: v0.1
    spec:
        containers:
        - name: liveness-tcpsocket-containter
          image: ikubernetes/myapp:v1
          ports:
          - name: http
            containerPort: 80
          livenessProbe:
            tcpSocket:
               port: http
            initialDelaySeconds: 3
            timeoutSeconds: 2
            failureThreshold: 3
        restartPolicy: Always

readiness ready detection

探测方式:
    命令探测方式:exec
              command
    请求业务:httpGet
              port
              path
    tcp套接字:tcpSocket
              port

常用字段:
       "readinessProbe:
        exec: #命令探测方式
          command: ["/bin/sh","-c","test -e /usr/share/nginx/html/index.html"]
        initialDelaySeconds: 3
        timeoutSeconds: 2
        failureThreshold: 3"              

就绪和存活探测示例:
apiVersion: v1
kind: Pod
metadata:
    name: readiness-httpget-pod
    namespace: default
    labels:
       version: v0.1
spec:
    containers:
    - name: readiness-httpget-containter
      image: ikubernetes/myapp:v1
      ports:
      - name: http
        containerPort: 80
      livenessProbe:
        httpGet:
           path: http://readiness-httpget-containter/index.html
           port: http
        initialDelaySeconds: 3
        timeoutSeconds: 2
        failureThreshold: 3
      readinessProbe:
        exec:
          command: ["/bin/sh","-c"," test -e /usr/share/nginx/html/index.html"]
        initialDelaySeconds: 3
        timeoutSeconds: 2
        failureThreshold: 3
    restartPolicy: Always

Define Pod Resource List

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
  namespace: default
  labels:
    apps: myapp
    tier: qianduan
重点字段 :
spec: <[]object 对象列表>
  containers: <[]Object> -required-  必选项
  - name:容器名称
    image: <镜像地址>
    imagePullPolicy: 镜像获取策略如always,Never,IfNotePresnt;
      说明:
      always:总是从仓库下载镜像,不管本地有没有
      Never:从不从仓库下载镜像
      IfNotPresnt: 如果本地有就用,没有就去仓库下载
    ports:  "注意:这里制定的端口没有实质性的作用,就算不指定端口容器也会暴漏端口"
    - name:端口名称,便于后续引用起来方便
      contiainerPort: 端口号
      "一个Pod内可以有多个容器"

Guess you like

Origin blog.51cto.com/13598893/2642214