The difference between ReplicaSet and ReplicaController Deployment, Service, Pod
1. Pod là thành phần đơn giản nhất: Nó như là 1 unit mà sẽ khởi chạy container
Trong 1 pod có thể chạy nhiều containers và share chung 1 network
apiVersion: batch/v1
kind: Job
metadata:
name: hello
spec:
template:
# This is the pod template
spec:
containers:
- name: hello
image: busybox
command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']
restartPolicy: OnFailure
# The pod template ends here
2. Tiếp theo để 1 pod chạy trên 1 port có thể giao tiếp với các pod khác trong 1 cluster thì cần phải expose nó như 1 service -> Service ra đời để mapping port của Pod ra port service mà các Pod khác có thể connect được với nhau
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
3. Vậy để quản lý việc nhân bản Pod khi scale hoặc là khi 1 pod bị die thì commponent nào trong K8s sẽ khởi tạo Pod thay thế , đó chính là Replicaset hoặc Replicacontroller
Khi bạn tạo ReplicaSet sẽ có 1 config là selector : matchLabels:
Tag này sẽ tìm các Pod có cùng label như vậy và để Replicaset quản lý việc nhân bản số lượng
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# modify replicas according to your case
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
4. Replicaset controller: cũng tương tự nhưng nó sẽ dùng tag: selector như bên dưới
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 3
selector:
app: nginx
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
5. Deployment: Là thành phần quan trọng tại sao nó có,
Khi tạo 1 deployment nó sẽ tạo ra 1 replicaSet để quản lý pod tương ứng và nó sẽ có thêm tính năng rollout và rollback trong khi replicaSet và controller k có tính năng rollout và rollback này
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Comments
Post a Comment