Our previous article covered Namespaces and Services and we are slowly increasing our knowledge of Kubernetes and how we can start to run our services on a basic environment. In todays article, we will explain to you how ReplicaSets and ReplicationControllers can be used to help you deploy your Pods and make sure they are always running. Don't worry, if you need to catch up a little, and are just starting out, checkout our previous posts that cover an [introduction to Kubernetes](https://stemgeeks.net/hive-163521/@run.vince.run/getting-started-with-kubernetes-basic-concepts-of-kubernetes), [Pods](https://stemgeeks.net/hive-163521/@run.vince.run/getting-started-with-kubernetes-deploy-pods), [Namespaces and Services](https://stemgeeks.net/hive-163521/@run.vince.run/getting-started-with-kubernetes-namespaces-and-services). <h2>ReplicaSets and ReplicationController</h2> If you create a Pod from a simple definition, you will have the issue occasionally where the pod could still go down and it would be lost, and you would need to restart it again from your Pod definition file. Instead of having to watch out for these events to happen, we can create our Pods as part of a ReplicaSet or ReplicationController. If the Pod then fails the replication controller, will bring up a new instance of the Pod. Replication controllers will also be able to spin up additional pods when the demand is needed. In this tutorial we will cover both ReplicationControllers and ReplicaSets, but note that the controllers are being replaced by ReplicaSets. A replication controller or replica set is created using a yaml to define how it will be set up, specifying the same details as we needed in our pod definition; apiVersion, kind, metadata and spec. In the definition below, we have set up our definition and in the spec of the ReplicationController, we have simply added the spec of our Pod that the controller will control, including the metadata and spec within the spec.template of the replication controller. We also need to include the replicas we need as part of our definition, in our case we have set โreplicas: 3โ. ``` 1 apiVersion: v1 2 kind: ReplicationController 3 metadata: 4 name: myapp-rc 5 labels: 6 app: myapp 7 type: front-end 8 spec: 9 template: 10 metadata: 11 name: nginx 12 labels: 13 app: myapp 14 spec: 15 containers: 16 - name: nginx-container 17 image: nginx 18 replicas: 3 19 ``` To then create the replication controller, you use the kubectl create command with the -f option and providing the yaml file we created. ``` kubeclt create -f <replication_controller_yaml> replicationcontroller/myapp-rc created ``` To see our replication controllers, we can use the get command below with the kubectl command: ``` kubectl get replicationcontroller NAME DESIRED CURRENT READY AGE myapp-rc 3 3 3 24s kubectl get pods NAME READY STATUS RESTARTS AGE myapp-rc-7l98t 1/1 Running 0 44s myapp-rc-s985r 1/1 Running 0 44s myapp-rc-xgxqm 1/1 Running 0 44s ``` A replica set is a little different were you also need to use the selector as we have in line 19 below to match the label of the pod we are going to be managing. ``` 1 apiVersion: apps/v1 2 kind: ReplicationSet 3 metadata: 4 name: myapp-replicaset 5 labels: 6 app: myapp 7 type: front-end 8 spec: 9 template: 10 metadata: 11 name: nginx 12 labels: 13 app: myapp 14 spec: 15 containers: 16 - name: nginx-container 17 image: nginx 18 replicas: 3 19 selector: 20 matchLabels: 21 type: front-end 22 ``` You then create the ReplicaSet the same way you would create any other definition file, but when you need to query a ReplicaSet, you would use the following kubectl command: ``` kubectl get replicaset ``` Scaling up your replicas can be done by editing the definition yaml file and then running the kubectl replace command: ``` kubectl replace -f <yaml_definition_file> ``` Or using the kubectl scale command as we have below: ``` kubectl scale --replicas=4 replicationcontroller myapp-rc replicationcontroller/myapp-rc scaled kubectl get pods NAME READY STATUS RESTARTS AGE myapp-rc-7l98t 1/1 Running 0 8m48s myapp-rc-s985r 1/1 Running 0 8m48s myapp-rc-td6mj 0/1 ContainerCreating 0 3s myapp-rc-xgxqm 1/1 Running 0 8m48s ``` Of course you can delete a ReplicaSet or ReplicationController by simply using the kubectl delete command, but remember, all the pods that the controllers manage, will also be deleted. ``` kubectl delete replicationcontroller myapp-rc replicationcontroller "myapp-rc" deleted kubectl get pods No resources found in default namespace. ``` Hopefully another piece to the puzzle, and hopefully you are seeing Kubernetes can actually be pretty clear and straight forward. Probably the reason why it has been adopted so quickly and is so popular. **About The Author I am a DevOps Engineer, Endurance Athlete and Author. As a DevOps Engineer I specialize in Linux and Open Source Applications. Particularly interested in Search Marketing and Analyticโs, and is currently developing my skills in devops, continuous integration, security, and development(Python).** Posted with [STEMGeeks](https://stemgeeks.net)
author | run.vince.run |
---|---|
permlink | getting-started-with-kubernetes-replicationcontrollers-and-replicasets |
category | hive-163521 |
json_metadata | {"tags":["runvincerun","kubernetes","k8s","coding","development","stem","technology"],"links":["https://stemgeeks.net/hive-163521/@run.vince.run/getting-started-with-kubernetes-basic-concepts-of-kubernetes"],"app":"stemgeeks/0.1","format":"markdown","canonical_url":"https://stemgeeks.net/@run.vince.run/getting-started-with-kubernetes-replicationcontrollers-and-replicasets"} |
created | 2022-12-20 08:09:06 |
last_update | 2022-12-20 08:09:06 |
depth | 0 |
children | 3 |
last_payout | 2022-12-27 08:09:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.272 HBD |
curator_payout_value | 0.264 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,534 |
author_reputation | 203,320,160,582,722 |
root_title | "Getting Started With Kubernetes - ReplicationControllers and ReplicaSets" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 119,246,682 |
net_rshares | 1,351,185,602,962 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
slider2990 | 0 | 5,311,377,837 | 100% | ||
teamaustralia | 0 | 10,274,239,044 | 45% | ||
joeyarnoldvn | 0 | 489,752,602 | 1.47% | ||
argon | 0 | 2,095,430,734 | 28% | ||
calatorulmiop | 0 | 116,925,796,801 | 100% | ||
plantstoplanks | 0 | 62,956,731,121 | 14% | ||
steemseph | 0 | 12,392,985,688 | 10% | ||
nathanpieters | 0 | 3,435,023,611 | 50% | ||
mrhill | 0 | 21,338,619,294 | 70% | ||
soluce07 | 0 | 2,601,172,659 | 50% | ||
jazzhero | 0 | 5,110,495,305 | 7.5% | ||
steemflagrewards | 0 | 376,571,770,427 | 100% | ||
sportfrei | 0 | 16,413,715,768 | 50% | ||
runningproject | 0 | 35,902,370,771 | 70% | ||
amico | 0 | 6,376,710,610 | 23.1% | ||
adamada | 0 | 55,694,653,095 | 10% | ||
run.vince.run | 0 | 45,423,408,574 | 100% | ||
enforcer48 | 0 | 222,063,511,475 | 20% | ||
pinas | 0 | 505,832,573 | 50% | ||
steem.girl | 0 | 494,711,398 | 100% | ||
sgbonus | 0 | 25,594,941,872 | 10% | ||
marenontherun | 0 | 6,981,428,454 | 35% | ||
bestofph | 0 | 1,298,742,719 | 10% | ||
admiralbot | 0 | 6,713,105,103 | 100% | ||
limka | 0 | 296,074,205 | 78.93% | ||
memehub | 0 | 97,445,347,502 | 100% | ||
aninsidejob | 0 | 6,954,960,334 | 100% | ||
ultratrain | 0 | 37,317,702,316 | 55% | ||
fitcoin | 0 | 536,147,149 | 100% | ||
amico.sports | 0 | 22,743,002,403 | 35% | ||
stemgeeks | 0 | 8,648,287,341 | 50% | ||
stemcuration | 0 | 48,943,762 | 50% | ||
babytarazkp | 0 | 3,426,533,677 | 40% | ||
abh12345.stem | 0 | 1,925,590,255 | 100% | ||
yggdrasil.laguna | 0 | 0 | 25% | ||
cd-stem | 0 | 516,813,801 | 100% | ||
chicoduro | 0 | 581,856,126 | 25% | ||
chapmain | 0 | 0 | 100% | ||
stuntman.mike | 0 | 5,487,875,182 | 100% | ||
manuvert | 0 | 26,007,062,651 | 30% | ||
dorkpower | 0 | 3,256,042,084 | 100% | ||
stemcur | 0 | 947,796,698 | 100% | ||
brofund-stem | 0 | 856,738,820 | 50% | ||
stemline | 0 | 3,224,905,503 | 25% | ||
sillybilly | 0 | 540,416,533 | 100% | ||
meestemboom | 0 | 476,296,103 | 25% | ||
scooter77.stem | 0 | 511,906,392 | 50% | ||
krishu.stem | 0 | 1,096,554,108 | 100% | ||
ruari | 0 | 621,193,028 | 100% | ||
peerfinance | 0 | 49,814,478,559 | 100% | ||
dronegirl | 0 | 287,394,708 | 100% | ||
adamada.stem | 0 | 3,224,832,415 | 100% | ||
juecoree.stem | 0 | 583,916,511 | 100% | ||
holovision.stem | 0 | 1,497,375,870 | 100% | ||
star.stem | 0 | 1,712,771,775 | 50% | ||
solominer.stem | 0 | 822,899,445 | 100% | ||
anonymous02 | 0 | 2,256,109,120 | 7.5% | ||
alzee | 0 | 14,003,245,257 | 75% | ||
svanbo | 0 | 4,514,645,940 | 15% | ||
saboin.stem | 0 | 400,840,460 | 50% | ||
gwajnberg | 0 | 5,632,519,394 | 55% | ||
stem-curator | 0 | 0 | 100% |
 | <div class="phishy"><u><h4>You have received a __1UP__ from @gwajnberg!</h4></u></div> The @oneup-cartel will soon upvote you with:<hr> __@stem-curator__ <hr>_And they will bring !PIZZA ๐._ -|- <sup>[Learn more](https://peakd.com/hive-102223/@flauwy/the-curation-cartel-1up-trigger-smart-voting-mana-and-high-delegation-returns-for-14-different-tribes) about our delegation service to earn daily rewards. Join the Cartel on [Discord](https://discord.gg/mvtAneE3Ca).</sup>
author | curation-cartel |
---|---|
permlink | re-getting-started-with-kubernetes-replicationcontrollers-and-replicasets-20221220t171435z |
category | hive-163521 |
json_metadata | "{"app": "beem/0.24.26"}" |
created | 2022-12-20 17:14:36 |
last_update | 2022-12-20 17:14:36 |
depth | 1 |
children | 0 |
last_payout | 2022-12-27 17:14:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 623 |
author_reputation | 1,123,882,653,763 |
root_title | "Getting Started With Kubernetes - ReplicationControllers and ReplicaSets" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 119,256,202 |
net_rshares | 44,323,554,235 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
run.vince.run | 0 | 44,323,554,235 | 100% |
thanks for the tutorial !1UP <a href="https://discord.gg/zQrvxAu7mu"> <img src="https://files.peakd.com/file/peakd-hive/thecuriousfool/23wCNFDyCLJu1v77TTg2MYKkd7XWkgF9fhiLujTDAaLaUz7H4AaQkDentB5UMVS8FcrVs.png"></a>
author | gwajnberg |
---|---|
permlink | rn790w |
category | hive-163521 |
json_metadata | {"tags":["stem"],"image":["https://files.peakd.com/file/peakd-hive/thecuriousfool/23wCNFDyCLJu1v77TTg2MYKkd7XWkgF9fhiLujTDAaLaUz7H4AaQkDentB5UMVS8FcrVs.png"],"links":["https://discord.gg/zQrvxAu7mu"],"app":"stemgeeks/0.1","canonical_url":"https://stemgeeks.net/@gwajnberg/rn790w"} |
created | 2022-12-20 17:10:09 |
last_update | 2022-12-20 17:10:09 |
depth | 1 |
children | 0 |
last_payout | 2022-12-27 17:10:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 214 |
author_reputation | 390,469,797,292,698 |
root_title | "Getting Started With Kubernetes - ReplicationControllers and ReplicaSets" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 119,256,123 |
net_rshares | 45,228,322,611 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
run.vince.run | 0 | 45,228,322,611 | 100% |
<center>๐ PIZZA ! I gifted <strong>$PIZZA</strong> slices here: @curation-cartel<sub>(9/20)</sub> tipped @run.vince.run (x1) <sub>Join us in <a href="https://discord.gg/hivepizza">Discord</a>!</sub></center>
author | pizzabot |
---|---|
permlink | re-getting-started-with-kubernetes-replicationcontrollers-and-replicasets-20221220t171456z |
category | hive-163521 |
json_metadata | "{"app": "beem/0.24.19"}" |
created | 2022-12-20 17:14:57 |
last_update | 2022-12-20 17:14:57 |
depth | 1 |
children | 0 |
last_payout | 2022-12-27 17:14:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 211 |
author_reputation | 7,698,943,017,949 |
root_title | "Getting Started With Kubernetes - ReplicationControllers and ReplicaSets" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 119,256,211 |
net_rshares | 0 |