Docker Cookbook


Starting Containers on a Kubernetes Cluster with Pods | 139



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

5.4 Starting Containers on a Kubernetes Cluster with Pods | 139


in the 
spec
section under the 
container
field. The image used and a name for the
container are required parameters. In this example, you also define port 80 to be
exposed and mapped on port 80 of the host (using the 
containerPort
and 
hostPort
keys).
You can then list the pods that you have running with 
kubectl get pods
. You will
see that the pod will enter running state, that there is one container in that pod, what
the image is, and its status:
$ kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST ...
podname 10.132.1.9 k8s-node/1.2.3.4 ...
2048 cpk1224/docker-2048 ...
To learn the API specification, you can query the pod and return its
definition in YAML or JSON:
$ ./kubectl get pods -o yaml 2048
apiVersion: v1
kind: Pod
metadata:
name: "2048"
...
The pod is exposed on port 80 on the host’s IP because of the 
host
Port
item in the original YAML pod definition file. This is great for
debugging but not recommended for production services, as each
host port can be forwarded to only a single container. To expose
pods in a more scalable way, use services as described in 
Recipe 5.2
.
Once you are done experimenting, you can delete the pod easily:
$ kubectl delete pods podname
5.5 Taking Advantage of Labels for Querying Kubernetes
Objects
Problem
In a large Kubernetes cluster, you may run thousands of pods as well as other cluster
objects. You would like to easily query and manipulate sets of objects in multi-
dimensional ways by using a tagging system.
140 | Chapter 5: Kubernetes


Solution
Tag your objects (e.g., pods) by using labels. 
Labels
are key/value pairs that can be
attached to any Kubernetes object. These labels are defined primarily in the metadata
section of an object definition.
Taking the example from 
Recipe 5.4
, you can add a label 
foo=bar
by modifying the
pod 
yaml
metadata description like so:
apiVersion: v1
kind: Pod
metadata:
name: 
"2048"
labels:
foo: bar
version: 
"47"
spec:
containers:
- image: cpk1224/docker-2048
name: 
"2048"
ports:
- containerPort: 80
hostPort: 80
Now delete any existing pod named 
2048
and start up a new pod with this definition.
The end result is that you can now list pods that have that specific label by using the
--selector
option of the 
kubectl
CLI:
$ kubectl get pods --selector="foo=bar"
Additionally, you can add labels at runtime by using the 
kubectl label
function:
$ kubectl label pods 2048 env=production
POD IP CONTAINER(S) IMAGE(S) HOST ...
2048 10.244.0.6 k8s-node/1.2.3.4 ...
2048 cpk1224/docker-2048
Labels follow a specific 
syntax
.
In short, labels are a straightforward tagging system that allows users to add metadata
to any resource in their cluster. It helps build cross-functional relationships to man‐
age sets of resources in various stages of an application life cycle.
Now delete your pod by identifying it via a label selector:
$ kubectl.sh delete pod --selector="foo=bar"
pods/2048

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   116   117   118   119   120   121   122   123   ...   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