Docker Cookbook


Taking Advantage of Labels for Querying Kubernetes Objects | 141



Download 6,31 Mb.
Pdf ko'rish
bet121/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   117   118   119   120   121   122   123   124   ...   260
Bog'liq
Docker Cookbook

5.5 Taking Advantage of Labels for Querying Kubernetes Objects | 141


See Also
• Introduction, motivation, and syntax of 
labels
5.6 Using a Replication Controller to Manage the Number
of Replicas of a Pod
Problem
You need to make sure that several replicas of your pod exist at any time in
the cluster.
Solution
Kubernetes is a declarative system: users express what they want the system to do and
not how to do it. Using replication controllers, you can specify the number of replicas
that you want for a pod. This helps with high load and availability by serving part of
an application through a service proxy (see 
Recipe 5.8
).
Replication controllers are one of the three key objects in a Kubernetes cluster (with
pods and services). You can list all running replication controllers with 
kubectl
:
$ kubectl get replicationcontrollers
...
$ kubectl get rc
To create a replication controller, you write a JSON or YAML file following the repli‐
cation controller API specification. It can contain metadata, the number of replicas
that you want, a selector to target specific pods, and a template for a pod. Currently,
the template is embedded within the replication controller definition, but this may
change in future version of Kubernetes.
For example, if you want to create a replication controller for the 2048 game that you
ran in a single pod in 
Recipe 5.4
, you can write the following 
rc2048.yaml
file:
apiVersion: v1
kind: ReplicationController
metadata:
labels:
name: rcgame
name: rcgame
spec:
replicas: 1
selector:
name: game
template:
metadata:
142 | Chapter 5: Kubernetes


labels:
name: game
spec:
containers:
- image: cpk1224/docker-2048
name: test
ports:
- containerPort: 80
The controller itself will have the 
rcgame
label, and will target pods with the label
game
. Once started, the controller will ensure that one pod is running at all times. You
launch it with 
kubectl create
:
$ kubectl create -f rc2048.yml
replicationcontrollers/rcgame
$ kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
rcgame test cpk1224/docker-2048 name=game 1
Try killing the pod that was created. You will see that a new one automatically starts
again.
You do not need to have an existing pod running before starting a
replication controller. It will automatically start a pod that matches
the label specified in the definition if it does not exist yet. You can
also set the number of replicas to zero.
The magic happens when you want to increase the number of replicas. You can use
the 
kubectl resize
command, and the number of pods will automatically be adjus‐
ted:
$ kubectl resize --replicas=4 rc rcgame
resized

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   117   118   119   120   121   122   123   124   ...   260




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish