• ReplicationController和ReplicaSet

    ReplicationController和ReplicaSet

    ReplicationCtronller用来确保容器应用的副本数始终保持在用户定义的副本数,即如果有容器异常退出,会自动创建新的Pod来替代;而如果异常多出来的容器也会自动回收。

    在新版本的Kubernetes中建议使用ReplicaSet来取代ReplicationCtronller。ReplicaSet跟ReplicationCtronller没有本质的不同,只是名字不一样,并且ReplicaSet支持集合式的selector。

    虽然ReplicaSet可以独立使用,但一般还是建议使用 Deployment 来自动管理ReplicaSet,这样就无需担心跟其他机制的不兼容问题(比如ReplicaSet不支持rolling-update但Deployment支持)。

    ReplicaSet示例:

    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