k8s learning - concept - ReplicationController

k8s learning - concept - ReplicationController

We have a pod, then you need to control the pod is podv the same services I need to start a few? If capacity is needed, and how to do? Here there is a controller, ReplicationController (referred to as rc).

But we Tell me what network:

Here to tell us, ReplicationController now obsolete, and now recommend the use of Deployment with ReplicaSet. The main function is to ensure that the number of ReplicationController Pod, healthy, resilient contraction. However Deployment In addition to these capabilities, but also increase the rollback feature (when upgraded pod mirroring or relevant parameters, if there is an error, you can roll back to a stable version), the version recorded (each operation are to Deployment can be preserved). Pause and boot (upgrade, can pause and start).

It estimated that in the near future, ReplicationController no one will use. But we understand some of the basic configuration of ReplicationController.

The following is the official ReplicationController a configuration file:

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

Spec.template which is the spec that must be filled out, it is a pod configuration. pod configuration complete works on one we saw.

.Spec.replicas which indicates that the need to maintain several pod. If no, then it is to 1. Such as the example above, 3 parts remains nginx service.

Tag selector

The selector which we can take here under study, this is the first time we met.

Tag selector in a lot of concepts are to use, such as pod on which node, ReplicationController role on which pod, service which acts on the pod, and so on. tag marked the systematic application of one cluster is k8s necessary design.

The tag selector to understand is actually very simple, just a bunch of key: value. For example, I can set the three label to the pod:

metadata:
  labels:
    key1: value1,
    key2: value2,
    key3: value3

key1=value1, key2=value2, key3=value3。

Then ReplicationController the selector inside, there are two ways for writing a simple writing, a high-level writing. (As if this argument is not online, but my understanding is this)

Write:

selector:
  key1: value1

Representative labels have selected this ReplicationController key1 label, and the label value of value1 control pod.

Senior wording :( this advanced written inside matchExpressions fact ReplicationController is not supported, ReplicaSet began to support. I do not know follow-up will not support a regular match)

selector:
  matchLabels:
    key1: value1
  matchExpressions:
    - {key: key2, operator: In, values: [value2, value4]}

Behalf of the selected labels ReplicationController label and tag values, key1: value1, value2 and the key2 pod set and value4 control.

We can bring resources in view of the time --show-labelsto get the labels, such as:

kubectl get pod --show-labels
NAME                            READY     STATUS    RESTARTS   AGE       LABELS
busybox                         1/1       Running   26         3d        <none>
busybox1                        1/1       Running   26         3d        name=busybox
busybox2                        1/1       Running   26         3d        name=busybox
frontend-5c548f4769-l9cts       1/1       Running   0          1h        app=guestbook,pod-template-hash=1710490325,tier=frontend
frontend-5c548f4769-nnp2b       1/1       Running   0          1h        app=guestbook,pod-template-hash=1710490325,tier=frontend
frontend-5c548f4769-zjwwm       1/1       Running   0          1h        app=guestbook,pod-template-hash=1710490325,tier=frontend
redis-master-55db5f7567-929np   1/1       Running   0          1h        app=redis,pod-template-hash=1186193123,role=master,tier=backend
redis-slave-584c66c5b5-dsbcc    1/1       Running   0          1h        app=redis,pod-template-hash=1407227161,role=slave,tier=backend
redis-slave-584c66c5b5-kfhnq    1/1       Running   0          1h        app=redis,pod-template-hash=1407227161,role=slave,tier=backend
task-pv-pod                     1/1       Running   0          1d        <none>

Although official website recommends a number of labels

"release" : "stable", "release" : "canary"
"environment" : "dev", "environment" : "qa", "environment" : "production"
"tier" : "frontend", "tier" : "backend", "tier" : "cache"
"partition" : "customerA", "partition" : "customerB"
"track" : "daily", "track" : "weekly"

But I feel we have the time to write a cluster of labels did not follow the recommendations. Basically a cluster has its own set design.

to sum up

Finally, in summary, ReplicationController this has been eliminated, and even demo k8s official website have all switched to the deployment + replicaset, so helpful ReplicationController encounter books and articles can be read abandoned.

- Current Date: July 9, 2019

Guess you like

Origin www.cnblogs.com/yjf512/p/11198733.html