k8sk8s容器专题-Kubernetes系列

k8s基础知识总结

2020-02-18  本文已影响0人  LLyang碎碎念

k8s入门知识点

[TOC]

k8s并不神秘,你可以结合vm和redis之类的中间件

Q-1:为什么需要k8s

Q0:k8s架构,k8s基本概念入门

Q1:k8s的yml讲解。

Q2:k8s能做什么?k8s如何做?

推荐官方文档和中文文档:

1.为什么需要k8s

来个官方链接:https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

2.基本架构和基本概念入门

2.1基本架构

对比几张来自不同网站的架构图

Kubernetes的组成

[图片上传失败...(image-eb049d-1582014664031)]

必须包含master和node 各至少一个。

image-20200206141241312

2.2 k8s的对象模型

k8s可以看做是面向对象的,每类服务可看做是k8s的一个对象。这些对象由用户定义yaml,k8s的api负责创建。所有对象包含spec(规范)+status两类基本信息。

例如:k8s创建pod的api为:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#pod-v1-core

kubectl 也会将yaml转成json发送到master节点。

image-20200206162500055

k8s中常用的对象有pod、deployment、service、statefulSet等,每个对象至少包含3个metadata:namespace、name、uid。

2.2.1 k8s中常见的object kind:
img
2.2.2 k8s中有常见的metadata
2.2.3 k8s spec中常见的参数

2.3 k8s的ip模型

k8s的ip:

2.4 k8s的volume

k8s的volume和docker有所不同,v是独立于容器的,与pod声明周期相同,即pod删除空间也被删除。有多重类型

2.5 k8s port

Port,Targetport,Nodeport区别

service 暴露nodeport 到node上,node 接受request 之后通过kube-proxy 负载到具体的pod(iptables 或 ipvs)。

k8s端口

3.k8s yaml讲解

一个yaml通常如下:其中apiVersion、kind、metadata、spec(规格)是必填的项目。通常spec对于对象而言是能起决定性作用的描述。且对于pod、deployment、service等对象有各自特殊格式的spec。

3.1 Depolyment的yaml示例

Deployment API 版本对照表

Kubernetes 版本 Deployment 版本
v1.5-v1.15 extensions/v1beta1
v1.7-v1.15 apps/v1beta1
v1.8-v1.15 apps/v1beta2
v1.9+ apps/v1

这是sre定义的内容:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  labels:
    k8s-app: chainaccesspipe   # lables k-v形式供service selector选择
  name: chainaccesspipe
  namespace: chainaccess-dev  # 命名空间
    annotations:
        title: "这是个测试title"
        date: "2020/10/10 "
        status: "be happy"
        
spec:
  replicas: 1  # 副本数
  selector:
    matchLabels:
      k8s-app: chainaccesspipe  #template选择器
  template:
    metadata:
      labels:
        k8s-app: chainaccesspipe
    spec:
      initContainers: #初始化容器
      - image: www.xxx.com/middleware/sysctl:latest
        imagePullPolicy: Always
        name: sysctl
        resources:
          limits:
            cpu: 20m
            memory: 20Mi
          requests:
            cpu: 20m
            memory: 20Mi
        securityContext:
          privileged: true
          runAsUser: 0
      containers:
      - name: chainaccesspipe
        image: www.xxx.com/baseserver-dev/pipe:integration.0.9.1.0.0
       # resources:
       #   requests:
       #     memory: "2G"
       #     cpu: "350m"
       #   limits:
       #     memory: "2G"
       #     cpu: 1
#        livenessProbe:
#          httpGet:
#            path: /actuator/health
#            port: 8017
#          initialDelaySeconds: 150
#          periodSeconds: 5
#        readinessProbe:
#          httpGet:
#            path: /actuator/health
#            port: 8017
#          initialDelaySeconds: 150
#          periodSeconds: 3
        env: # 环境变量
        - name: LC_ALL
          value: en_US.utf8
        - name: JAVA_OPTS_OVERRIDE
          value: |-
            -Xms1024m
            -Xmx1024m
            -Dport=8017
            -Dnacos-namespace=5ea6a570-379f-4d74-9553-066a2227720f
            -Duser.timezone=GMT+08
        args:
        - -jar
        - /app/app.jar
        ports:
        - containerPort: 8017  #容器暴露端口
        imagePullPolicy: Always
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
      imagePullSecrets:
      - name: sec8084
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: chainaccesspipe
  annotations:
    prometheus.io/scrape: "true"
    prometheus.io/app-metrics-path: /actuator/prometheus
  name: chainaccesspipe
  namespace: chainaccess-dev
spec:
  ports:
    - port: 8017
      targetPort: 8017
      nodePort: 28017
  type: NodePort
  selector:
    k8s-app: chainaccesspipe

接下来我们登陆21 ,通过api获取下完整的map:

curl -s 127.0.0.1:8080/apis/apps/v1/namespaces/chainaccess-dev/deployments/chainaccesspipe  | jq 

内容如下,这个是v1版本下,完整的map,我们可以对比下定义的yaml。

{
  "kind": "Deployment",
  "apiVersion": "apps/v1",
  "metadata": {
    "name": "chainaccesspipe",
    "namespace": "chainaccess-dev",
    "selfLink": "/apis/apps/v1/namespaces/chainaccess-dev/deployments/chainaccesspipe",
    "uid": "9ca01515-2aca-11ea-b7ca-005056aa5684",
    "resourceVersion": "84030034",
    "generation": 1,
    "creationTimestamp": "2019-12-30T06:07:08Z",
    "labels": {
      "k8s-app": "chainaccesspipe"
    },
    "annotations": {
      "deployment.kubernetes.io/revision": "1"
    }
  },
  "spec": {
    "replicas": 1,
    "selector": {
      "matchLabels": {
        "k8s-app": "chainaccesspipe"
      }
    },
    "template": {
      "metadata": {
        "creationTimestamp": null,
        "labels": {
          "k8s-app": "chainaccesspipe"
        }
      },
      "spec": {
        "initContainers": [
          {
            "name": "sysctl",
            "image": "harbor.xxx.com/middleware/sysctl:latest",
            "resources": {
              "limits": {
                "cpu": "20m",
                "memory": "20Mi"
              },
              "requests": {
                "cpu": "20m",
                "memory": "20Mi"
              }
            },
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "Always",
            "securityContext": {
              "privileged": true,
              "runAsUser": 0
            }
          }
        ],
        "containers": [
          {
            "name": "chainaccesspipe",
            "image": "harbor.xxx.com/baseserver-dev/pipe:release.0.9.1.1.0",
            "args": [
              "-jar",
              "/app/app.jar"
            ],
            "ports": [
              {
                "containerPort": 8080,
                "protocol": "TCP"
              }
            ],
            "env": [
              {
                "name": "LC_ALL",
                "value": "en_US.utf8"
              },
              {
                "name": "JAVA_OPTS_OVERRIDE",
                "value": "-Xms1024m\n-Xmx1024m\n-Dport=8080\n-Dnacos-server-addr=nacos-headless.nacos-server:8848\n-Dnacos-namespace=9482afb2-3267-45ea-92cd-48edaae5837b\n-Duser.timezone=GMT+08"
              }
            ],
            "resources": {},
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "Always"
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {
          "runAsUser": 1000,
          "fsGroup": 1000
        },
        "imagePullSecrets": [
          {
            "name": "sec8084"
          }
        ],
        "schedulerName": "default-scheduler"
      }
    },
    "strategy": {
      "type": "RollingUpdate",
      "rollingUpdate": {
        "maxUnavailable": "25%",
        "maxSurge": "25%"
      }
    },
    "revisionHistoryLimit": 10,
    "progressDeadlineSeconds": 600
  },
  "status": {
    "observedGeneration": 1,
    "replicas": 1,
    "updatedReplicas": 1,
    "readyReplicas": 1,
    "availableReplicas": 1,
    "conditions": [
      {
        "type": "Progressing",
        "status": "True",
        "lastUpdateTime": "2019-12-30T06:07:17Z",
        "lastTransitionTime": "2019-12-30T06:07:08Z",
        "reason": "NewReplicaSetAvailable",
        "message": "ReplicaSet \"chainaccesspipe-6bf9469bf4\" has successfully progressed."
      },
      {
        "type": "Available",
        "status": "True",
        "lastUpdateTime": "2020-01-19T08:10:00Z",
        "lastTransitionTime": "2020-01-19T08:10:00Z",
        "reason": "MinimumReplicasAvailable",
        "message": "Deployment has minimum availability."
      }
    ]
  }
}

3.2 pod完整yaml

apiVersion: v1                    #必选,版本号,例如v1,版本号必须可以用 kubectl api-versions 查询到 .
kind: Pod                      #必选,Pod
metadata:                      #必选,元数据
  name: string                    #必选,Pod名称
  namespace: string               #必选,Pod所属的命名空间,默认为"default"
  labels:                       #自定义标签
    - name: string                 #自定义标签名字
  annotations:                           #自定义注释列表
    - name: string
spec:                            #必选,Pod中容器的详细定义
  containers:                       #必选,Pod中容器列表
  - name: string                        #必选,容器名称,需符合RFC 1035规范
    image: string                       #必选,容器的镜像名称
    imagePullPolicy: [ Always|Never|IfNotPresent ]  #获取镜像的策略 Alawys表示下载镜像 IfnotPresent表示优先使用本地镜像,否则下载镜像,Nerver表示仅使用本地镜像
    command: [string]               #容器的启动命令列表,如不指定,使用打包时使用的启动命令
    args: [string]                     #容器的启动命令参数列表
    workingDir: string                     #容器的工作目录
    volumeMounts:                 #挂载到容器内部的存储卷配置
    - name: string                 #引用pod定义的共享存储卷的名称,需用volumes[]部分定义的的卷名
      mountPath: string                 #存储卷在容器内mount的绝对路径,应少于512字符
      readOnly: boolean                 #是否为只读模式
    ports:                      #需要暴露的端口库号列表
    - name: string                 #端口的名称
      containerPort: int                #容器需要监听的端口号
      hostPort: int                    #容器所在主机需要监听的端口号,默认与Container相同
      protocol: string                  #端口协议,支持TCP和UDP,默认TCP
    env:                          #容器运行前需设置的环境变量列表
    - name: string                    #环境变量名称
      value: string                   #环境变量的值
    resources:                          #资源限制和请求的设置
      limits:                       #资源限制的设置
        cpu: string                   #Cpu的限制,单位为core数,将用于docker run --cpu-shares参数
        memory: string                  #内存限制,单位可以为Mib/Gib,将用于docker run --memory参数
      requests:                         #资源请求的设置
        cpu: string                   #Cpu请求,容器启动的初始可用数量
        memory: string                    #内存请求,容器启动的初始可用数量
    livenessProbe:                    #对Pod内各容器健康检查的设置,当探测无响应几次后将自动重启该容器,检查方法有exec、httpGet和tcpSocket,对一个容器只需设置其中一种方法即可
      exec:                     #对Pod容器内检查方式设置为exec方式
        command: [string]               #exec方式需要制定的命令或脚本
      httpGet:                    #对Pod内个容器健康检查方法设置为HttpGet,需要制定Path、port
        path: string
        port: number
        host: string
        scheme: string
        HttpHeaders:
        - name: string
          value: string
      tcpSocket:            #对Pod内个容器健康检查方式设置为tcpSocket方式
         port: number
       initialDelaySeconds: 0       #容器启动完成后首次探测的时间,单位为秒
       timeoutSeconds: 0          #对容器健康检查探测等待响应的超时时间,单位秒,默认1秒
       periodSeconds: 0           #对容器监控检查的定期探测时间设置,单位秒,默认10秒一次
       successThreshold: 0
       failureThreshold: 0
       securityContext:
         privileged: false
    restartPolicy: [Always | Never | OnFailure] #Pod的重启策略,Always表示一旦不管以何种方式终止运行,kubelet都将重启,OnFailure表示只有Pod以非0退出码退出才重启,Nerver表示不再重启该Pod
    nodeSelector: obeject         #设置NodeSelector表示将该Pod调度到包含这个label的node上,以key:value的格式指定
    imagePullSecrets:         #Pull镜像时使用的secret名称,以key:secretkey格式指定
    - name: string
    hostNetwork: false            #是否使用主机网络模式,默认为false,如果设置为true,表示使用宿主机网络
    volumes:                  #在该pod上定义共享存储卷列表
    - name: string              #共享存储卷名称 (volumes类型有很多种)
      emptyDir: {}              #类型为emtyDir的存储卷,与Pod同生命周期的一个临时目录。为空值
      hostPath: string            #类型为hostPath的存储卷,表示挂载Pod所在宿主机的目录
        path: string                #Pod所在宿主机的目录,将被用于同期中mount的目录
      secret:                 #类型为secret的存储卷,挂载集群与定义的secre对象到容器内部
        scretname: string  
        items:     
        - key: string
          path: string
      configMap:                      #类型为configMap的存储卷,挂载预定义的configMap对象到容器内部
        name: string
        items:
        - key: string
          path: string

附录:

附录1:k8s常见api操作

# 查看当前集群支持的API版本
$ curl -s 127.0.0.1:8080/api/ | jq -r .versions

# 查看指定API的资源操作类型 返回一个字典列表
$ curl -s 127.0.0.1:8080/api/v1/ | jq keys
[
  "groupVersion",
  "kind",
  "resources"
]

# 查看当前k8s集群支持的操作类型
curl -s 127.0.0.1:8080/api/v1/ | jq .resources | grep "name\b"
    "name": "bindings",
    "name": "componentstatuses",
    "name": "configmaps",
    "name": "endpoints",
    "name": "events",
    "name": "limitranges",
    "name": "namespaces",
    "name": "namespaces/finalize",
    "name": "namespaces/status",
    "name": "nodes",
    "name": "nodes/proxy",
    "name": "nodes/status",
    "name": "persistentvolumeclaims",
    "name": "persistentvolumeclaims/status",
    "name": "persistentvolumes",
    "name": "persistentvolumes/status",
    "name": "pods",
    "name": "pods/attach",
    "name": "pods/binding",
    "name": "pods/eviction",
    "name": "pods/exec",
    "name": "pods/log",
    "name": "pods/portforward",
    "name": "pods/proxy",
    "name": "pods/status",
    "name": "podtemplates",
    "name": "replicationcontrollers",
    "name": "replicationcontrollers/scale",
    "name": "replicationcontrollers/status",
    "name": "resourcequotas",
    "name": "resourcequotas/status",
    "name": "secrets",
    "name": "serviceaccounts",
    "name": "services",
    "name": "services/proxy",
    "name": "services/status",

# 常用的,需要关注的几个资源类型 【namespaces|nodes|pods|podtemplates|replicationcontrollers|services|secrets】

# 查看某个namespace的URL
$ curl -s 127.0.0.1:8080/api/v1/namespaces/ | jq .items | jq values[0]  | grep -E '(name|selfLink)'
    "name": "default",
    "selfLink": "/api/v1/namespaces/default",

# 查看namespace详情
$ curl -s 127.0.0.1:8080/api/v1/namespaces/default | jq .spec
{
  "finalizers": [
    "kubernetes"
  ]
}




# 查看全部node
$ curl -s 127.0.0.1:8080/api/v1/nodes | jq .items | grep -E "\bname\b|selfLink"
      "name": "172.25.47.138",
      "selfLink": "/api/v1/nodes/172.25.47.138",
      "name": "172.25.47.202",
      "selfLink": "/api/v1/nodes/172.25.47.202",
      "name": "172.25.47.75",
      "selfLink": "/api/v1/nodes/172.25.47.75",
      "name": "10.0.0.121",
      "selfLink": "/api/v1/nodes/10.0.0.121",
      "name": "10.0.0.122",
      "selfLink": "/api/v1/nodes/10.0.0.122",

# 查看某个node详情【当前该节点的资源信息以及设置限制条件,当前节点运行的pod容器以及镜像相关信息】
$ curl -s 127.0.0.1:8080/api/v1/nodes/10.0.0.122 | jq .status
{
  "capacity": {
    "cpu": "4",
    "ephemeral-storage": "14987616Ki",
    "hugepages-2Mi": "0",
    "memory": "6627524Ki",
    "pods": "110"
  },
  "allocatable": {
    "cpu": "4",
    "ephemeral-storage": "13812586883",
    "hugepages-2Mi": "0",
    "memory": "6525124Ki",
    "pods": "110"
  },
  "conditions": [
    {
      "type": "OutOfDisk",
      "status": "False",
      "lastHeartbeatTime": "2018-07-19T03:15:50Z",
      "lastTransitionTime": "2018-06-28T01:59:06Z",
      "reason": "KubeletHasSufficientDisk",
      "message": "kubelet has sufficient disk space available"
    },
    {
      "type": "MemoryPressure",
      "status": "False",
      "lastHeartbeatTime": "2018-07-19T03:15:50Z",
      "lastTransitionTime": "2018-06-28T01:59:06Z",
      "reason": "KubeletHasSufficientMemory",
      "message": "kubelet has sufficient memory available"
    },
    {
      "type": "DiskPressure",
      "status": "False",
      "lastHeartbeatTime": "2018-07-19T03:15:50Z",
      "lastTransitionTime": "2018-06-28T01:59:06Z",
      "reason": "KubeletHasNoDiskPressure",
      "message": "kubelet has no disk pressure"
    },
    {
      "type": "PIDPressure",
      "status": "False",
      "lastHeartbeatTime": "2018-07-19T03:15:50Z",
      "lastTransitionTime": "2018-06-28T01:59:06Z",
      "reason": "KubeletHasSufficientPID",
      "message": "kubelet has sufficient PID available"
    },
    {
      "type": "Ready",
      "status": "True",
      "lastHeartbeatTime": "2018-07-19T03:15:50Z",
      "lastTransitionTime": "2018-07-18T08:18:31Z",
      "reason": "KubeletReady",
      "message": "kubelet is posting ready status"
    }
  ],
  "addresses": [
    {
      "type": "InternalIP",
      "address": "10.0.0.122"
    },
    {
      "type": "Hostname",
      "address": "10.0.0.122"
    }
  ],
  "daemonEndpoints": {
    "kubeletEndpoint": {
      "Port": 10250
    }
  },
  "nodeInfo": {
    "machineID": "cd7f16da1665b7cee74f46122e2d7cdd",
    "systemUUID": "0E96FBAF-C214-18F8-D9E6-8B65B9B5A413",
    "bootID": "f67f0185-4be6-41d0-b5e0-d126165f6986",
    "kernelVersion": "3.10.0-327.el7.x86_64",
    "osImage": "CentOS Linux 7 (Core)",
    "containerRuntimeVersion": "docker://1.12.6",
    "kubeletVersion": "v1.10.4",
    "kubeProxyVersion": "v1.10.4",
    "operatingSystem": "linux",
    "architecture": "amd64"
  },
  "images": [
    {
      "names": [
        "dockerhub.jd.com/wolf/fe-wolf@sha256:0b155e99f27de990cfd3a5f96bcc13b820530cf1236b96ca5d87efae4f65f62a",
        "dockerhub.jd.com/wolf/fe-wolf:latest"
      ],
      "sizeBytes": 352597644
    },
    {
      "names": [
        "xxbandy123/go-web@sha256:c375b479a74b0ec77608a221a28ddc4589149d55a04845eac697903add557c30",
        "xxbandy123/go-web:latest"
      ],
      "sizeBytes": 338268706
    },
    {
      "names": [
        "dockerhub.jd.com/gcr_mirror/pause-amd64@sha256:fcaff905397ba63fd376d0c3019f1f1cb6e7506131389edbcb3d22719f1ae54d",
        "dockerhub.jd.com/gcr_mirror/pause-amd64:3.1"
      ],
      "sizeBytes": 742472
    }
  ]
}


# 查看pod相关信息【由于一般k8s是不建议使用pod类型来直接控制容器的,因此这个接口直接查没什么意义】

# 查看apis group相关信息
curl -s 127.0.0.1:8080/apis/extensions/v1beta1 | grep "\bname\b"
      "name": "daemonsets",
      "name": "daemonsets/status",
      "name": "deployments",
      "name": "deployments/rollback",
      "name": "deployments/scale",
      "name": "deployments/status",
      "name": "ingresses",
      "name": "ingresses/status",
      "name": "networkpolicies",
      "name": "podsecuritypolicies",
      "name": "replicasets",
      "name": "replicasets/scale",
      "name": "replicasets/status",
      "name": "replicationcontrollers",
      "name": "replicationcontrollers/scale",
$ curl -s 127.0.0.1:8080/apis/apps/v1beta1 | grep "\bname\b"
      "name": "controllerrevisions",
      "name": "deployments",
      "name": "deployments/rollback",
      "name": "deployments/scale",
      "name": "deployments/status",
      "name": "statefulsets",
      "name": "statefulsets/scale",
      "name": "statefulsets/status",





# 查看控制器对应的控制器信息【statefulset,deployment】 这些控制器的信息一般在/apis/apps/下
# job和cronjob一般会在/apis/batch/下
$ curl -s 127.0.0.1:8080/apis/batch/v1 | grep "\bname\b"
      "name": "jobs",
      "name": "jobs/status",

curl -s 127.0.0.1:8080/apis/batch/v1/jobs | jq -r .items | grep name
      "name": "image-build-service",
      "namespace": "default",
      "selfLink": "/apis/batch/v1/namespaces/default/jobs/image-build-service",
        "job-name": "image-build-service"
          "name": "image-build-service",
            "job-name": "image-build-service"
              "name": "hosts",
              "name": "image-build-service",
                  "name": "dockerhost",
                  "name": "branch",
                  "name": "giturl",
                  "name": "app",
                  "name": "dockerfiledir",
                  "name": "hosts",



# 查看当前/apis/apps/支持的apiversion
$ curl -s 127.0.0.1:8080/apis/apps | jq .versions |grep "groupVersion"
    "groupVersion": "apps/v1",
    "groupVersion": "apps/v1beta2",
    "groupVersion": "apps/v1beta1",

# 查看应用的api支持的相关资源类型 【daemonsets|deployments|replicasets|statefulsets】
$ curl -s 127.0.0.1:8080/apis/apps/v1 | jq .resources | grep "name\b"
    "name": "controllerrevisions",
    "name": "daemonsets",
    "name": "daemonsets/status",
    "name": "deployments",
    "name": "deployments/scale",
    "name": "deployments/status",
    "name": "replicasets",
    "name": "replicasets/scale",
    "name": "replicasets/status",
    "name": "statefulsets",
    "name": "statefulsets/scale",
    "name": "statefulsets/status",

# 问题:job类型的资源在哪里查看 batch/extension?

# 查看deployment名称和selflink
$ curl -s 127.0.0.1:8080/apis/apps/v1/deployments | jq .items | grep   -E "(\bname\b|\bnamespace\b|selfLink)"
      "name": "test-go-web",
      "namespace": "default",
      "selfLink": "/apis/apps/v1/namespaces/default/deployments/test-go-web",

# 查看某个deployment详情
$ kubectl get deployments -o wide
NAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS    IMAGES                         SELECTOR
test-go-web   5         5         5            5           1h        test-go-web   xxbandy123/go-web   run=test-go-web
$ curl -s 127.0.0.1:8080/apis/apps/v1/namespaces/default/deployments/test-go-web  | jq .spec
{
  "replicas": 5,
  "selector": {
    "matchLabels": {
      "run": "test-go-web"
    }
  },
  "template": {
    "metadata": {
      "creationTimestamp": null,
      "labels": {
        "run": "test-go-web"
      }
    },
    "spec": {
      "containers": [
        {
          "name": "test-go-web",
          "image": "xxbandy123/go-web",
          "ports": [
            {
              "containerPort": 9090,
              "protocol": "TCP"
            }
          ],
          "resources": {},
          "terminationMessagePath": "/dev/termination-log",
          "terminationMessagePolicy": "File",
          "imagePullPolicy": "Always"
        }
      ],
      "restartPolicy": "Always",
      "terminationGracePeriodSeconds": 30,
      "dnsPolicy": "ClusterFirst",
      "securityContext": {},
      "schedulerName": "default-scheduler"
    }
  },
  "strategy": {
    "type": "RollingUpdate",
    "rollingUpdate": {
      "maxUnavailable": 1,
      "maxSurge": 1
    }
  },
  "revisionHistoryLimit": 10,
  "progressDeadlineSeconds": 600
}




# 查看service资源下的实例
# curl -s 127.0.0.1:8080/api/v1/services/ | jq ".items" | jq values[1] |grep -E "(\bname\b|selfLink|\bnamespace\b)"
    "name": "test-go-web",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/test-go-web",

# 查看某个service详情 【具体的资源类型会被划分到namespaces下】
$ curl -s 127.0.0.1:8080/api/v1/namespaces/default/services/test-go-web | jq -r '.spec'
{
  "ports": [
    {
      "protocol": "TCP",
      "port": 9090,
      "targetPort": 9090,
      "nodePort": 30315
    }
  ],
  "selector": {
    "run": "test-go-web"
  },
  "clusterIP": "10.254.141.49",
  "type": "NodePort",
  "sessionAffinity": "None",
  "externalTrafficPolicy": "Cluster"
}


# 查看configmap
$ curl -s 127.0.0.1:8080/api/v1/configmaps | jq .items

# 查看secrets
$ curl -s 127.0.0.1:8080/api/v1/secrets | jq .items | grep "\"\bname\b"



附录2:参考资料:

上一篇下一篇

猜你喜欢

热点阅读