Kubenetes资源

常用资源对象

  • workload: Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob
  • 负载均衡/服务发现:Service, Ingress, ...
  • 配置与存储: Volume, CSI
    • cronfigMap,Secret
    • DownwardAPI
  • 集群级别资源
    • Namespace, node, role, ClusterRole, RoleBinding , ClusterRoleBinding
  • 元数据型资源
    • HPA, PodTemplate, LimitRange

标签labels

labels 与 资源之间是多对多的关系

标签的定义一般从以下几个角度定义

  • 版本:alpha beta canary stable
  • 环境:dev pro qa
  • 应用名称
  • 架构层级
  • 分区标签
  • 品控标签

标签格式:

  1. key=value
  2. key: 字母 数字 _ .
  3. value:只能以字母数字开头及结尾

通过标签过滤

  1. kubectl get pods -l <labels>

查看所有标签

  1. kubectl get pods --show-labels

打标签

  1. kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N
  2. [--resource-version=version] [options]

标签选择器

  • 等值关系:=, ==,!=

  • 集合关系:

    KEY in (VALUE1,VALUE2, ... )

    KEY not in (VALUE1,VALUE2, ... )

    !KEY * 不存在键

许多资源支持内嵌字段

  • matchLabels: 直接给定健值

  • matchExpressions: 基于给定的表达式来定义使用标签选择器,{key:"KEY", operator: "OPERATOR", values:[VAL1, VAL2, ...]}

    操作符:In, NotIn, Exists, NotExists

创建资源的方式

apiserver仅接受JSON格式的资源定义;

yaml格式提供配置清单, apiserver可自动将其转为json格式,然后提交

大部分的资源的配置清单,主要5个一级资源

  • apiVersion

    1. kubectl api-versions
  • kind: 资源类别

  • metadata: 元数据

    • name

    • namespace

    • labels

    • annotations

    每个资源的引用PATH 路径

    /api/GROUP/VERSION/namespaces/NAMESPACE_NAME/TYPE/NAME

  • spec

  • status

使用explain 查看定义

例如:

  1. kubectl explain pods.metadata
  2. kubectl explain pods.spec.containers

Pod

k8s管理的最小单位,一个pod中可以有多个contaiers 例如

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: nginx
  5. spec:
  6. containers:
  7. - name: nginx
  8. image: nginx:1.7.9
  9. ports:
  10. - containerPort: 80
  11. readinessProbe:
  12. httpGet:
  13. port: 80
  14. initialDelaySeconds: 2
  15. periodSeconds: 3
  16. livenessProbe:
  17. httpGet:
  18. port: 80
  19. initialDelaySeconds: 2
  20. periodSeconds: 3
  21. - name: busybox
  22. image: busybox:latest
  23. imagePullPolicy: IfNotPresent
  24. command: ['/bin/sh','-c','ping','www.baidu.com']
  25. nodeSelector:
  26. kubernetes.io/hostname: 192.168.0.165

pods.spec.containers 必须

  1. - name <string>
  2. image <string>
  3. imagePullPolicy <string> Always, Never, IfNotPresent.
  4. * Defaults to Always if :latest tag is specified, or IfNotPresent otherwise. Cannot be updated. (优化点)
  5. ports <[]Object>
  6. * 仅仅是说明性的
  7. - containerPort <integer> -required-
  8. hostIP 0.0.0.0
  9. hostPort 必须与containerPort 相同,大部分不需要定义该项
  10. name 名称
  11. protocol 默认TCP
  • 修改容器的启动命令
  1. command <[]string>
  2. args <[]string>
  3. - command 会覆盖镜像中的Entrypoint command
  4. - args 会覆盖镜像中的 command
  5. https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/

nodeSelector <map [string]string>

节点选择器, 限定pod运行在哪些节点上。

使用标签选择器

nodeName<map [string]string>

直接选择节点

annotations

注解,仅用于提供”元数据“并不提供 资源兑现选择。没有大小限制。

restartPolicy

Always, OnFailure, Never Default to Always

hostNetwork

Host networking requested for this pod. Use the host's network namespace.If this option is set, the ports that will be used must be specified. Default to false.

pod直接使用主机的网络名称空间。有用但不常用,默认false。

pod的生命周期

  • 串行执行多个 init_containters(初始化容器),初始化容器执行完成后退出。
  • 启动主容器 main containters
  • 启动后可以执行 post start
  • 主进程执行时可以进行健康监测包括:liveness probe 与 readness probe
  • 结束前可以执行 pre stop

状态

  • Pending 等待调度,调度未完成
  • Running 运行状态
  • Failed 失败
  • Succeeded
  • Unknown

创建Pod:

apiServer etcd scheduler controller kubelet

容器重启策略

restartPolicy

健康监测

健康监测主要针对容器,所以在 pod.spec.containers 层级下

监测类型

  • livenessProbe 存活性探测
  • readinessProbe 就绪性监测
  • lifecycle 容器启动后 或者 停止前钩子。

存活并不一定就绪

三种探针类型

ExecAction (exec)、TCPSocketAction (tcpSocket)、HTTPGetAction(httpGet)

健康监测主要参数

  1. - exec <Object> 使用命令监测 (重要)
  2. - command <[]string>
  3. - httpGet
  4. - tcpSocket
  5. - initialDelaySeconds (重要) 初始化等待时间
  6. - periodSeconds (重要) 检测间隔时间
  7. - timeoutSeconds <integer> 错误超时时间 默认1
  8. - failureThreshold <integer> 最小失败次数 默认3
  9. - successThreshold <integer> 最小成功次数 默认1

lifecycle

容器启动后 或者 停止前钩子。

  • postStart
  • preStop

    注意:lifecycle的postStart执行在容器command 之后。

FIELDS:

  1. - exec <Object>
  2. - httpGet <Object> HTTPGet specifies the http request to perform.

env环境变量获取

env不仅可以传递key value 的数据,还可以从其他地方传值传递。

pods.spec.containers.env.valueFrom

  1. - configMapKeyRef
  2. Selects a key of a ConfigMap.
  3. - fieldRef <Object>
  4. Selects a field of the pod: supports metadata.name, metadata.namespace, metadata.labels, metadata.annotations, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP.
  5. - resourceFieldRef <Object>
  6. Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
  7. - secretKeyRef <Object>
  8. Selects a key of a secret in the pod's namespace

pod 案例

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: nginx
  5. spec:
  6. containers:
  7. - name: nginx
  8. image: nginx:1.7.9
  9. ports:
  10. - containerPort: 80
  11. readinessProbe:
  12. httpGet:
  13. port: 80
  14. initialDelaySeconds: 2
  15. periodSeconds: 3
  16. livenessProbe:
  17. httpGet:
  18. port: 80
  19. initialDelaySeconds: 2
  20. periodSeconds: 3
  21. - name: busybox
  22. image: busybox:latest
  23. imagePullPolicy: IfNotPresent
  24. command: [ping, www.baidu.com]
  25. nodeSelector:
  26. kubernetes.io/hostname: 192.168.0.165

Pod控制器

  • ReplicaSet: 控制pod 副本数量,扩缩容机制
  • Deployment:ReplicaSet的控制器, 滚动更新、回滚, 声明式定义。无状态服务
  • DaemonSet: 确保每个节点执行一个
  • Job : 执行一次
  • CronJob : 计划任务
  • StatefuleSet:有状态的服务
  • CDR: Custom Defined Resources
  • Operator
  1. 用户应该直接操作Deployment。
  2. 最好不要将有状态的服务部署在k8s上

deployment

更新策略

deployment.spec.strategy

  • Recreate
  • RollingUpdate
  • maxSurge Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
  • maxUnavailable Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).

    deployment.spec.revisionHistoryLimit

    rc历史保存数量

案例:

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. author: huruizhi
  6. department: opreation
  7. usage: Java programs k8s template
  8. labels:
  9. module_name: pyfinance2v2-register-pro
  10. env: pro
  11. kind: deploy
  12. name: pyfinance2v2-register-pro
  13. namespace: default
  14. spec:
  15. replicas: 4
  16. strategy:
  17. type: RollingUpdate
  18. rollingUpdate:
  19. maxSurge: 2
  20. maxUnavailable: 2
  21. selector:
  22. matchLabels:
  23. module_name: pyfinance2v2-register-pro
  24. env: pro
  25. kind: pod
  26. template:
  27. metadata:
  28. creationTimestamp: null
  29. labels:
  30. module_name: pyfinance2v2-register-pro
  31. env: pro
  32. kind: pod
  33. spec:
  34. containers:
  35. - name: pyfinance2v2-register-pro
  36. image: harbor.pycf.com/pyfinance2v2/register:pro
  37. imagePullPolicy: Always
  38. ports:
  39. - containerPort: 5000
  40. command: ['java','-jar','-Xms128m','-Xmx256m','/java8/app.jar','--server.port=5000']
  41. resources:
  42. limits:
  43. memory: 512Mi
  44. requests:
  45. memory: 128Mi
  46. env:
  47. - name: TZ
  48. value: Asia/Shanghai
  49. livenessProbe:
  50. tcpSocket:
  51. port: 5000
  52. initialDelaySeconds: 40
  53. periodSeconds: 3
  54. readinessProbe:
  55. tcpSocket:
  56. port: 5000
  57. initialDelaySeconds: 40
  58. periodSeconds: 3
  59. imagePullSecrets:
  60. - name: harborkey1
  61. restartPolicy: Always

DaemSet

在每个节点上部署一个pod

支持滚动更新,支持两种更新模式。可以使用kubectl explain daemonset.spec.updateStrategy 查看。

手动更新 kubectl set image daemonset abc *=nginx:1.9.1

案例:

  1. apiVersion: extensions/v1beta1
  2. kind: DaemonSet
  3. metadata:
  4. name: filefeat-ds
  5. namespace: default
  6. labels:
  7. app: filebeat
  8. spec:
  9. selector:
  10. matchLabels:
  11. app: filebeat
  12. release: stable
  13. template:
  14. metadata:
  15. labels:
  16. app: filebeat
  17. release: stable
  18. spec:
  19. containers:
  20. - name: filefeat
  21. image: ikubenetes/filebeat:5.6.5-alpine
  22. env:
  23. - name: REDIS_HOST
  24. value: redis.default.svc.cluster.local
  25. - name: REDIS_LOG_LEVEL
  26. value: info

Service

Service的名称解析依赖于dns 附件,网络依赖于第三方网络方案。

Service网络是一个虚拟网络,由kube-proxy维护。

工作模式:

  • iptables
  • ipvs

ipvs没有被激活的情况下自动使用iptables

iptables 查看:

iptables -L -n -t nat

svc.spec的重要字段

  • ClusterIP 一般不手动指定,可以指定为None 则为无头svc。

    设置成无头svc后 dns中的A记录为pod IP地址,A记录的数量与pod数量相当

    例如使用dig命令查看

    1. # dig pyfinance2v2-register-pro.default.svc.cluster.local. @172.20.162.187
    2. ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> pyfinance2v2-register-pro.default.svc.cluster.local. @172.20.162.187
    3. ;; global options: +cmd
    4. ;; Got answer:
    5. ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3070
    6. ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
    7. ;; OPT PSEUDOSECTION:
    8. ; EDNS: version: 0, flags:; udp: 4096
    9. ;; QUESTION SECTION:
    10. ;pyfinance2v2-register-pro.default.svc.cluster.local. IN A
    11. ;; ANSWER SECTION:
    12. pyfinance2v2-register-pro.default.svc.cluster.local. 5 IN A 172.20.197.37
    13. pyfinance2v2-register-pro.default.svc.cluster.local. 5 IN A 172.20.229.141
    14. pyfinance2v2-register-pro.default.svc.cluster.local. 5 IN A 172.20.41.13
    15. ;; Query time: 2 msec
    16. ;; SERVER: 172.20.162.187#53(172.20.162.187)
    17. ;; WHEN: Wed Feb 13 10:23:49 CST 2019
    18. ;; MSG SIZE rcvd: 281
  • ports <[]Object>

    • port
    • nodePort
    • targetPort
  • selector

  • type : ExternalName(访问外部服务 例如 GlusterFs), ClusterIP, NodePort, and LoadBalancer( 外部负载均衡 ).

  • healthCheckNodePort

  • sessionAffinity :ClientIP 和 None ,负载均衡调度策略。设置为ClientIP 则将同一个ip的连接发送到后端同一个pod上。

域名后缀

默认为svc_name.namespace_name.svc.cluster.local.

案例:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. annotations:
  5. kompose.cmd: kompose convert -f docker-compose-pro.yml
  6. kompose.version: 1.7.0 (HEAD)
  7. creationTimestamp: null
  8. labels:
  9. io.kompose.service: pyfinance2v2-amc-pro
  10. name: pyfinance2v2-amc-pro
  11. namespace: pyfinance2v2-pro
  12. spec:
  13. type: NodePort
  14. ports:
  15. - name: "7562"
  16. port: 7562
  17. targetPort: 5000
  18. nodePort: 7562
  19. selector:
  20. io.kompose.service: pyfinance2v2-amc-pro
  21. status:
  22. loadBalancer: {}

Ingress Controller

外部路由引入,7层负载均衡,可以进行https 卸载。

案例:

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: my-nginx-ingress
  5. namespace: default
  6. spec:
  7. rules:
  8. - host: my-nginx.com
  9. http:
  10. paths:
  11. - path: /main
  12. backend:
  13. serviceName: my-nginx
  14. servicePort: 80
  15. - path: /busybox
  16. backend:
  17. serviceName: busybox-demo
  18. servicePort: 80

path: Path is an extended POSIX regex as defined by IEEE Std 1003.1, (i.e this follows the egrep/unix syntax, not the perl syntax) matched against the path of an incoming request. Currently it can contain characters disallowed from the conventional "path" part of a URL as defined by RFC 3986. Paths must begin with a '/'. If unspecified, the path defaults to a catch all sending traffic to the backend.

例如 path 设置为 /main 则可以访问 /main /main1 等。不能访问 / 、/aaa 等其他路径下资源

存储卷管理

  • emptyDir 临时存储目录
  • hostPath 主机存储
  • 网络共享存储: SAN NAS 分布式存储(glusterfs rbd cephfs ...) 云存储

支持的存储卷类型

  1. kubectl explain pod.spec.volumes
  2. kubectl explain persistentVolume.spec

定义一个简单的emptyDir, 包涵两个containers。两个容器公用存储卷。

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: busybox-demo
  5. labels:
  6. app: busybox
  7. role: volume_test
  8. spec:
  9. containers:
  10. - name: httpd
  11. image: nginx:latest
  12. imagePullPolicy: IfNotPresent
  13. volumeMounts:
  14. - mountPath: /usr/share/nginx/html/
  15. name: tmp-volume
  16. - name: busybox
  17. image: busybox:latest
  18. imagePullPolicy: IfNotPresent
  19. command: ['/bin/sh','-c','while true;do echo $(date) > /data/index.html;sleep 3;done']
  20. volumeMounts:
  21. - mountPath: /data/
  22. name: tmp-volume
  23. volumes:
  24. - name: tmp-volume
  25. emptyDir:
  26. sizeLimit: 200M

PV 与 PVC 资源

PV对象 及 主要参数

PV对象不属于名称空间

pv.Capacity

通过capacity给PV设置特定的大小。

pv.accessModes

k8s不会真正检查存储的访问模式或根据访问模式做访问限制,只是对真实存储的描述,最终的控制权在真实的存储端。目前支持三种访问模式:

* ReadWriteOnce – PV以 read-write 挂载到一个节点

* ReadOnlyMany – PV以read-only方式挂载到多个节点

* ReadWriteMany – PV以read-write方式挂载到多个节点

pv.spec.persistentVolumeReclaimPolicy

当前支持的回收策略:

* Retain – 允许用户手动回收

* Recycle – 删除PV上的数据 (“rm -rf /thevolume/*”)

* Delete – 删除PV

PVC对象 与重要参数

PVC 与PV对象 关联

pvc.spec.accessModes

同 pv对象

pvc.spec.resources

  • limits
  • requests

定义存储大小的需要

案例 Glusterfs:

  1. apiVersion: v1
  2. kind: Endpoints
  3. metadata:
  4. name: gfs-endpoint
  5. labels:
  6. storage: gfs
  7. subsets:
  8. - addresses:
  9. - ip: 192.168.0.165
  10. ports:
  11. - port: 49158
  12. protocol: TCP
  13. - addresses:
  14. - ip: 192.168.0.162
  15. - ip: 192.168.0.166
  16. ports:
  17. - port: 49157
  18. protocol: TCP
  19. ---
  20. apiVersion: v1
  21. kind: PersistentVolumeClaim
  22. metadata:
  23. name: gfs-pvc
  24. spec:
  25. accessModes:
  26. - ReadWriteMany
  27. volumeName: gfs-pv
  28. resources:
  29. requests:
  30. storage: 20Gi
  31. ---
  32. apiVersion: v1
  33. kind: PersistentVolume
  34. metadata:
  35. name: gfs-pv
  36. labels:
  37. role: gfs-pv
  38. spec:
  39. accessModes:
  40. - ReadWriteMany
  41. glusterfs:
  42. endpoints: gfs-endpoint
  43. path: gluster-test
  44. capacity:
  45. storage: 20Gi
  46. ---
  47. apiVersion: v1
  48. kind: PersistentVolumeClaim
  49. metadata:
  50. name: gfs-pvc
  51. spec:
  52. accessModes:
  53. - ReadWriteMany
  54. volumeName: gfs-pv
  55. resources:
  56. requests:
  57. storage: 20Gi
  58. ---
  59. apiVersion: v1
  60. kind: Pod
  61. metadata:
  62. name: busybox-demo
  63. labels:
  64. app: busybox
  65. role: volume_test
  66. spec:
  67. containers:
  68. - name: httpd
  69. image: nginx:latest
  70. imagePullPolicy: IfNotPresent
  71. volumeMounts:
  72. - mountPath: /usr/share/nginx/html/busybox
  73. name: gfs-volume
  74. - name: busybox
  75. image: busybox:latest
  76. imagePullPolicy: IfNotPresent
  77. command: ['/bin/sh','-c','while true;do echo $(date) >> /data/index.html;sleep 3;done']
  78. volumeMounts:
  79. - mountPath: /data/
  80. name: gfs-volume
  81. volumes:
  82. - name: gfs-volume
  83. persistentVolumeClaim:
  84. claimName: gfs-pvc

StorageClass 动态生成pv

容器配置管理 secret 与 configmap

可以使用环境变量以及 挂载的方式配置到pod当中。

注意:环境变量的方式只能在容器启动的时候注入,更新configmap 不会更新容器中环境变量的值。使用挂载的方式可以实时更新。

创建configMap 有多种方式

  • 使用kubectl create命令行方式
  1. # Create a new configmap named my-config based on folder bar
  2. kubectl create configmap my-config --from-file=path/to/bar
  3. # Create a new configmap named my-config with specified keys instead of file basenames on disk
  4. kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
  5. # Create a new configmap named my-config with key1=config1 and key2=config2
  6. kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2
  7. # Create a new configmap named my-config from the key=value pairs in the file
  8. kubectl create configmap my-config --from-file=path/to/bar
  9. # Create a new configmap named my-config from an env file
  10. kubectl create configmap my-config --from-env-file=path/to/bar.env
  • 使用yaml文件
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: test-cfg
  5. namespace: default
  6. data:
  7. cache_host: memcached-gcxt
  8. cache_port: "11211"
  9. cache_prefix: gcxt
  10. my.cnf: |
  11. [mysqld]
  12. log-bin = mysql-bin
  13. app.properties: |
  14. property.1 = value-1
  15. property.2 = value-2
  16. property.3 = value-3

使用命令行创建更灵活。

可以使用inotify监控配置文件实现重载

例如:

  1. #!/bin/sh
  2. oldcksum=`cksum /etc/nginx/conf.d/default.conf`
  3. inotifywait -e modify,move,create,delete -mr --timefmt '%d/%m/%y %H:%M' --format '%T' \
  4. /etc/nginx/conf.d/ | while read date time; do
  5. newcksum=`cksum /etc/nginx/conf.d/default.conf`
  6. if [ "$newcksum" != "$oldcksum" ]; then
  7. echo "At ${time} on ${date}, config file update detected."
  8. oldcksum=$newcksum
  9. nginx -s reload
  10. fi
  11. done

关于configmap的详细总结: https://www.cnblogs.com/breezey/p/6582082.html

StatefuleSet

特点:

  1. 稳定且唯一的网络标识符;
  2. 稳定且持久的存储;
  3. 有序、平滑的部署和扩展;
  4. 有序、平滑的删除和终止;
  5. 有序的滚动更新;

三个主要组件:headless service 、 StatefulSet、 volumeClaimTemplate

名称解析:

pod_name,service_name.ns_name.svc.cluster.local

更新策略

sts.spec.updateStrategy.rollingUpdate

  • partition 定义更新的边界,例如 定义为3 则编号 >=3的 pod会更新,模拟金丝雀发布

PV定义

  1. apiVersion: v1
  2. kind: Endpoints
  3. metadata:
  4. name: gfs-endpoint
  5. labels:
  6. storage: gfs
  7. subsets:
  8. - addresses:
  9. - ip: 192.168.0.165
  10. ports:
  11. - port: 49158
  12. protocol: TCP
  13. - addresses:
  14. - ip: 192.168.0.162
  15. - ip: 192.168.0.166
  16. ports:
  17. - port: 49157
  18. protocol: TCP
  19. ---
  20. apiVersion: v1
  21. kind: PersistentVolume
  22. metadata:
  23. name: gfs-pv-01
  24. labels:
  25. role: gfs-pv-01
  26. spec:
  27. accessModes:
  28. - ReadWriteMany
  29. - ReadWriteOnce
  30. glusterfs:
  31. endpoints: gfs-endpoint
  32. path: pv-01
  33. capacity:
  34. storage: 5Gi
  35. ---
  36. apiVersion: v1
  37. kind: PersistentVolume
  38. metadata:
  39. name: gfs-pv-02
  40. labels:
  41. role: gfs-pv-02
  42. spec:
  43. accessModes:
  44. - ReadWriteMany
  45. - ReadWriteOnce
  46. glusterfs:
  47. endpoints: gfs-endpoint
  48. path: pv-02
  49. capacity:
  50. storage: 5Gi
  51. ---
  52. apiVersion: v1
  53. kind: PersistentVolume
  54. metadata:
  55. name: gfs-pv-03
  56. labels:
  57. role: gfs-pv-03
  58. spec:
  59. accessModes:
  60. - ReadWriteMany
  61. - ReadWriteOnce
  62. glusterfs:
  63. endpoints: gfs-endpoint
  64. path: pv-03
  65. capacity:
  66. storage: 5Gi
  67. ---
  68. apiVersion: v1
  69. kind: PersistentVolume
  70. metadata:
  71. name: gfs-pv-04
  72. labels:
  73. role: gfs-pv-04
  74. spec:
  75. accessModes:
  76. - ReadWriteMany
  77. - ReadWriteOnce
  78. glusterfs:
  79. endpoints: gfs-endpoint
  80. path: pv-04
  81. capacity:
  82. storage: 5Gi
  83. ---
  84. apiVersion: v1
  85. kind: PersistentVolume
  86. metadata:
  87. name: gfs-pv-05
  88. labels:
  89. role: gfs-pv-05
  90. spec:
  91. accessModes:
  92. - ReadWriteMany
  93. - ReadWriteOnce
  94. glusterfs:
  95. endpoints: gfs-endpoint
  96. path: pv-05
  97. capacity:
  98. storage: 5Gi

StatefulSet定义

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: myapp-svc
  5. labels:
  6. roles: myapp-svc-test
  7. spec:
  8. clusterIP: None
  9. ports:
  10. - targetPort: 80
  11. port: 80
  12. selector:
  13. roles: myapp-pod
  14. ---
  15. apiVersion: apps/v1
  16. kind: StatefulSet
  17. metadata:
  18. name: myapp-sts
  19. labels:
  20. roles: myapp-sts-test
  21. spec:
  22. replicas: 3
  23. serviceName: myapp-svc
  24. selector:
  25. matchLabels:
  26. roles: myapp-pod
  27. template:
  28. metadata:
  29. labels:
  30. roles: myapp-pod
  31. spec:
  32. containers:
  33. - name: httpd
  34. image: nginx:latest
  35. imagePullPolicy: IfNotPresent
  36. volumeMounts:
  37. - mountPath: /usr/share/nginx/html/busybox
  38. name: gfs-volume
  39. volumeClaimTemplates:
  40. - metadata:
  41. name: gfs-volume
  42. spec:
  43. accessModes: [ "ReadWriteOnce" ]
  44. resources:
  45. requests:
  46. storage: 5Gi
  47. updateStrategy:
  48. rollingUpdate:
  49. partition: 2

02-Kubenetes资源的更多相关文章

  1. Kubenetes 资源清单定义入门

    Kubernetes 常用资源 资源  对象 工作负载型资源对象(workload): Pod  Replicaset  ReplicationController  Deployments Stat ...

  2. Java笔记 #02# 带资源的try语句

    索引 普通的 try.java 带资源的 try.java 当资源为 null 的情况 可以参考的文档与资料 / test.txt 待读取的内容 hello. / 普通的 try.java 读取 te ...

  3. SpringMVC04controller中定义多个方法

    public class MyController extends MultiActionController { // 新增 方法修饰符要是public public ModelAndView ad ...

  4. jdbc01

    1.创建对应的数据库以及表 /* SQLyog 企业版 - MySQL GUI v8.14 MySQL - 5.5.32-log : Database - news ***************** ...

  5. java操作oracle空间信息介绍

    转自:http://www.cdtarena.com/javapx/201307/9088.html sde是Spatial Database Engine简写,中文全称:空间数据库引擎. SDE是一 ...

  6. HTTP&HTTPS协议详解之HTTP篇

    一.HTTP简介 01.什么是HTTP HTTP(HyperText Transfer Protocol ,超文本传输协议),是一个基于请求与响应的,无状态的,应用层的协议,常基于TCP/IP协议传输 ...

  7. 基于Containerd安装部署高可用Kubernetes集群

    转载自:https://blog.weiyigeek.top/2021/7-30-623.html 简述 Kubernetes(后续简称k8s)是 Google(2014年6月) 开源的一个容器编排引 ...

  8. 读书分享全网学习资源大合集,推荐Python3标准库等五本书「02」

    0.前言 在此之前,我已经为准备学习python的小白同学们准备了轻量级但超无敌的python开发利器之visio studio code使用入门系列.详见 1.PYTHON开发利器之VS Code使 ...

  9. K8S(02)管理核心资源的三种基本方法

    系列文章说明 本系列文章,可以基本算是 老男孩2019年王硕的K8S周末班课程 笔记,根据视频来看本笔记最好,否则有些地方会看不明白 需要视频可以联系我 管理k8s核心资源的三种基本方法: 目录 系列 ...

随机推荐

  1. 第五章 .net core该怎么玩

    项目目标部署环境:CentOS 7+ 项目技术点:.netcore2.0 + Autofac +webAPI + NHibernate5.1 + mysql5.6 + nginx 开源地址:https ...

  2. Tido 习题-二叉树-区间查询

    题目描述 食堂有N个打饭窗口,现在正到了午饭时间,每个窗口都排了很多的学生,而且每个窗口排队的人数在不断的变化.现在问你第i个窗口到第j个窗口一共有多少人在排队? 输入 输入的第一行是一个整数T,表示 ...

  3. Dynamics 365 Document Management

    Dynamics CRM中的Document Management功能需要Dynamics CRM与SharePoint进行集成,也就是实现在CRM中上传Document,实际上Document最终存 ...

  4. Laravel --- Laravel 5.3 队列使用方法

    一.设置存储方式 在config/queue.php中查看队列驱动,在.env 设置[QUEUE_DRIVER] 主要介绍数据库驱动 二.数据库驱动 1.修改.env CACHE_DRIVER=fil ...

  5. Java学习笔记——设计模式之七.模板方法模式

    模板方法模式(TemplateMethod),定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 结构图: 代码: 算法骨架 ...

  6. CentOS7 搭建gitlab服务器

    本文介绍如何在CentOS7.2上搭建Gitlab服务器,并简单介绍如何使用. Preface 使用的是CentOS7.2的操作系统,安装当前最新版Gitlab服务器,下载地址:清华大学开源软件镜像站 ...

  7. Python文件中将print的输出内容重定向到变量中

    有时候需要用到别人的代码, 但是又不想修改别人的文件, 想拿到输出的结果, 这时候就需要使用sys模块, 将print输出的内容重定向到变量中. Python调用sys模块中的sys.stdout, ...

  8. TCP/IP 第四、五章

    1, 2, 整个arp请求的过程. 3,arp -a 获取arp高速缓存.一般arp高速缓存存活时间20分钟,不完整的表项设置为3分钟.因为机器的ip地址可能发生改变. 4, 5,arp一般是操作系统 ...

  9. java虚拟机-程序计数器PC Register

    什么是程序计数器? 程序计数器是一块 较小 的内存空间,它可以看做是当前线程所执行的字节码的 行号指示器 :在虚拟机的概念模型里(仅仅是概念模型,各种虚拟机可能会通过一些更高效的方式去实现),字节码解 ...

  10. F#周报2019年第28期

    新闻 FableConf门票开始贩售 Bolero的HTML模板支持热加载 Bolero从v0.4到v0.5的升级指南 完整的SAFE-Chat迁移至了Fable 2 为纯函数式3D图形生成领域专用语 ...