Replication controller in kubernetes

No comments
Kubernetes is a technology which is some what difficult to understand.But if you have proper understanding then you will feel very easy to implement.

Some times we are facing problem in understanding replicationcontroller in kubernetes.
Today we'll drill down to one step for understanding kubernetes replication controller.

Sample replication controller 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

Overall view

  1. Replication controller make insures that number of specified pods running in the cluster OR homogeneous set of pods are always up and available.
  2. use a replication controller even if your application requires only a single pod.
  3. If there are too many pods, it will kill some. If there are too few, the replication controller will start more.


Syntax of myapp-rc.yaml file

Before going ahead it's very important to understand syntax and terminology of replicationcontroller file.
  1. apiVersion,kind,metadata,spec will come in one alignment as green colour in ablove file
  2. metadata can contain name,label of replicationcontroller
  3. all the specification of replication controller will come under spec section
  4. spec mainly contains three information replicas,selector,template
  5. number of replicas means number of pods which cluster will contain each time.
  6. selector means pod will contain only those containers whose label we have mentioned in spec.template.metadata.labels
      7.template mainly contains two keywords metadata and spec 
Labels on the Replication Controller

The replication controller can itself have labels (.metadata.labels). Typically, you would set these the same as the .spec.template.metadata.labels; if .metadata.labels is not specified then it is defaulted to .spec.template.metadata.labels. However, they are allowed to be different, and the .metadata.labels do not affec the behavior of the replication controller.

Pod Selector

The .spec.selector field is a label selector. A replication controller manages all the pods with labels which match the selector. It does not distinguish between pods which it created or deleted versus pods which some other person or process created or deleted. This allows the replication controller to be replaced without affecting the running pods.
If specified, the .spec.template.metadata.labels must be equal to the .spec.selector, or it will be rejected by the API. If .spec.selector is unspecified, it will be defaulted to .spec.template.metadata.labels.

Multiple Replicas

You can specify how many pods should run concurrently by setting .spec.replicas to the number of pods you would like to have running concurrently. The number running at any time may be higher or lower, such as if the replicas was just increased or decreased, or if a pod is gracefully shutdown, and a replacement starts early.

If you do not specify .spec.replicas, then it defaults to 1.











No comments :

Post a Comment