0% found this document useful (0 votes)
8 views5 pages

PDF 12-Writing YAML Files

The document provides a comprehensive guide on creating and managing Kubernetes deployments using YAML files, including steps to create a deployment and service, verify their creation, and expose pods to the outside world. It also covers resource management by restricting CPU and RAM usage, as well as installing and testing a metrics server for monitoring. Key commands and YAML structures are included to facilitate the deployment process.

Uploaded by

chinnakumark8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

PDF 12-Writing YAML Files

The document provides a comprehensive guide on creating and managing Kubernetes deployments using YAML files, including steps to create a deployment and service, verify their creation, and expose pods to the outside world. It also covers resource management by restricting CPU and RAM usage, as well as installing and testing a metrics server for monitoring. Key commands and YAML structures are included to facilitate the deployment process.

Uploaded by

chinnakumark8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Writing YAML

YAML Structures

1 kind:
2 apiVersion:
3 metadata:
4 name:
5 labels:
6 label:
7 spec:
8 replicas:
9 strategy:
10 selector:
11 matchLabels:
12 label:
13 template:
14 metadata:
15 labels:
16 label:
17 spec:
18 containers:
19 - name:
20 image:
21 command:
22 args:
23 workingDir:
24 ports:
25 env:
26 resources:
27 volumeMounts:
28 livenessProbe:
29 readinessProbe:
30 lifecycle:
31 terminationMessagePath:
32 imagePullPolicy:
33 securityContext:
34 stdin:
35 stdinOnce:
36 tty:

Identification of the objects we create in Kubernetes

Deploy and test:

Step-1 Create a deployment YAML file called deployment-corpwebsite.yaml

1 sudo nano deployment-corpwebsite.yaml

1 apiVersion: apps/v1
2 kind: Deployment
3 metadata:
4 name: deployment-corpwebsite
5 spec:
6 selector:
7 matchLabels:
8 app: pod-corpwebsite
9 replicas: 2
10 template:
11 metadata:
12 labels:
13 app: pod-corpwebsite
14 env: dev
15 spec:
16 containers:
17 - name: container-corpwebsite
18 image: tanvisinghny/ssl-website
19 ports:
20 - containerPort: 80
21 - containerPort: 443

Step-2 Apply this file to create deployment

1 kubectl apply -f deployment-corpwebsite.yaml

Step-3 Verify the Pods creation

1 linuxadmin@master:~$ kubectl get pods


2 NAME READY STATUS RESTARTS AGE
3 deployment-corpwebsite-7675c48cc6-6zn5d 1/1 Running 0 81m
4 deployment-corpwebsite-7675c48cc6-rl4sh 1/1 Running 0 81m

Step-4 Verify Deployment Object creation


1 linuxadmin@master:~$ kubectl get deployments
2 NAME READY UP-TO-DATE AVAILABLE AGE
3 deployment-corpwebsite 2/2 2 2 24h

Step-5 Verify that a Replica Set is created

1 linuxadmin@master:~$ kubectl get rs


2 NAME DESIRED CURRENT READY AGE
3 deployment-corpwebsite-7675c48cc6 2 2 2 82m
4 deployment-corpwebsite-7f948548fd 0 0 0 24h

Filter Pods by Label env=dev

1 linuxadmin@master:~$ kubectl get pods -l env=dev


2 NAME READY STATUS RESTARTS AGE
3 deployment-corpwebsite-7675c48cc6-6zn5d 1/1 Running 0 83m
4 deployment-corpwebsite-7675c48cc6-rl4sh 1/1 Running 0 83m

POD Name
<DeploymentName>.<RandomString>

Random String Rules

To prevent “bad words”, vowels and the numbers 0, 1 and 3 were removed from the rand.String function
So, the <RandomString> will be composed by a combination of the following alphanumeric characters: bcdfghjklmnpqrstvwxz2456789

Is POD NAME so important?

For Kubernetes POD name is irrelevant.


Kubernetes always identifes PODs by LABEL.

Observe our POD names here:

1 linuxadmin@master:~$ kubectl get pods


2 NAME READY STATUS RESTARTS AGE
3 deployment-corpwebsite-7675c48cc6-6zn5d 1/1 Running 0 84m
4 deployment-corpwebsite-7675c48cc6-rl4sh 1/1 Running 0 84m

Exposing the PODs to outside world


Create a service YAMl file:

1 sudo nano service-corpwebsite.yaml

1 apiVersion: v1
2 kind: Service
3 metadata:
4 name: service-corpwebsite
5 spec:
6 type: NodePort
7 selector:
8 app: pod-corpwebsite
9 ports:
10 - nodePort: 30163
11 port: 443
12 targetPort: 443
13 externalIPs:
14 - 165.232.184.39
15 - 139.59.19.74
16

External IPs are Worker Node IPs:

1 externalIPs:
2 - 165.232.184.39
3 - 139.59.19.74

Type of Service is NodePort indicating PODs can be accessed from Internet using Workernode IPs and Ports

Note that the POD is identified by it’s LABEL: app: pod-corpwebsite

1 spec:
2 type: NodePort
3 selector:
4 app: pod-corpwebsite

Apply the Service:

1 kubectl apply -f service-corpwebsite.yml

Find if the Service is created:

1 linuxadmin@master:~$ kubectl get svc


2 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
3 kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 36h
4 service-corpwebsite NodePort 10.109.37.230 165.232.184.39,139.59.19.74 443:30163/TCP 22h

Restrict POD CPU, RAM usage


Change the Deployment file to include CPU, RAM Metrics:

1 apiVersion: apps/v1
2 kind: Deployment
3 metadata:
4 name: deployment-corpwebsite
5 spec:
6 selector:
7 matchLabels:
8 app: pod-corpwebsite
9 replicas: 2 # tells deployment to run 2 pods matching the template
10 template:
11 metadata:
12 labels:
13 app: pod-corpwebsite
14 env: dev
15 spec:
16 containers:
17 - name: container-corpwebsite
18 image: tanvisinghny/ssl-website
19 ports:
20 - containerPort: 80
21 - containerPort: 443
22 resources:
23 limits:
24 memory: 200Mi
25 cpu: 300m
26 requests:
27 memory: 100Mi
28 cpu: 100m

Note we added these filelds:

1 resources:
2 limits:
3 memory: 200Mi
4 pu: 300m
5 requests:
6 memory: 100Mi
7 cpu: 100m

Built-in Kubernetes Metrics


Install Metrics-Server Components:

curl -LO https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

1 curl -LO https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Edit the file and these metrics:

1 sudo nano components.yaml

Once done, apply the changes:

1 kubectl apply -f components.yaml

Verify if Metrics-Server is Running

1 kubectl get pods -n kube-system

Test Metrics Server Installation

1 kubectl top nodes

1 kubectl top pod

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy