一、ReplicaSet

RS主要被Deployments用作Pod机制的创建、删除和更新,但也可以独立使用。
通过编写yaml文件,可以确保运行指定数量的Pod:

  1. apiVersion: extensions/v1beta1
  2. kind: ReplicaSet
  3. metadata:
  4. name: frontend
  5. # these labels can be applied automatically
  6. # from the labels in the pod template if not set
  7. # labels:
  8. # app: guestbook
  9. # tier: frontend
  10. spec:
  11. # this replicas value is default
  12. # modify it according to your case
  13. replicas: 3
  14. # selector can be applied automatically
  15. # from the labels in the pod template if not set,
  16. # but we are specifying the selector here to
  17. # demonstrate its usage.
  18. selector:
  19. matchLabels:
  20. tier: frontend
  21. matchExpressions:
  22. - {key: tier, operator: In, values: [frontend]}
  23. template:
  24. metadata:
  25. labels:
  26. app: guestbook
  27. tier: frontend
  28. spec:
  29. containers:
  30. - name: php-redis
  31. image: gcr.io/google_samples/gb-frontend:v3
  32. resources:
  33. requests:
  34. cpu: 100m
  35. memory: 100Mi
  36. env:
  37. - name: GET_HOSTS_FROM
  38. value: dns
  39. # If your cluster config does not include a dns service, then to
  40. # instead access environment variables to find service host
  41. # info, comment out the 'value: dns' line above, and uncomment the
  42. # line below.
  43. # value: env
  44. ports:
  45. - containerPort: 80

与Deployment创建一样,读入yaml解析为结构体,调用接口创建ReplicaSet及其管理的Pod

image.png

同样的,也提供了删、改、查的方法

二、StatefulSet

StatefulSets是有状态系统服务设计
编写yaml文件创建:

  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4. name: tds-web
  5. spec:
  6. serviceName: demo-service
  7. replicas: 2
  8. selector:
  9. matchLabels:
  10. app: nginx
  11. template:
  12. metadata:
  13. labels:
  14. app: nginx
  15. spec:
  16. containers:
  17. - name: nginx
  18. image: k8s.gcr.io/nginx-slim:0.8
  19. ports:
  20. - containerPort: 80
  21. name: web
  22. volumeMounts:
  23. - name: www
  24. mountPath: /usr/share/nginx/html

同样的,也提供了删、改、查的方法

三、DaemonSet

DaemonSet 确保全部(或者一些)Node 上运行一个 Pod 的副本。当有 Node 加入集群时,也会为他们新增一个 Pod 。当有 Node 从集群移除时,这些 Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod。

编写yaml创建:

  1. apiVersion: extensions/v1beta1
  2. kind: DaemonSet
  3. metadata:
  4. name: tds-daemonset
  5. spec:
  6. template:
  7. metadata:
  8. labels:
  9. app: logging
  10. id: fluentd
  11. name: fluentd
  12. spec:
  13. containers:
  14. - name: fluentd-es
  15. image: gcr.io/google_containers/fluentd-elasticsearch:1.3
  16. env:
  17. - name: FLUENTD_ARGS
  18. value: -qq
  19. volumeMounts:
  20. - name: containers
  21. mountPath: /var/lib/docker/containers
  22. - name: varlog
  23. mountPath: /varlog
  24. volumes:
  25. - hostPath:
  26. path: /var/lib/docker/containers
  27. name: containers
  28. - hostPath:
  29. path: /var/log
  30. name: varlog

同样的,也提供了删、改、查的方法