0% found this document useful (0 votes)
40 views19 pages

PDF 13-Yaml Files

The document provides a comprehensive guide on deploying Kubernetes objects, specifically focusing on writing YAML files for POD deployment and service configuration. It outlines the structure of YAML files, including required fields and resource limits, as well as instructions for verifying resource limits and installing a metrics server. Additionally, it explains how to access PODs and manage traffic routing within a Kubernetes cluster.

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)
40 views19 pages

PDF 13-Yaml Files

The document provides a comprehensive guide on deploying Kubernetes objects, specifically focusing on writing YAML files for POD deployment and service configuration. It outlines the structure of YAML files, including required fields and resource limits, as well as instructions for verifying resource limits and installing a metrics server. Additionally, it explains how to access PODs and manage traffic routing within a Kubernetes cluster.

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/ 19

CloudIQ

Kubernetes
CloudIQ

Writing
YAML Files
Deploying Kubernetes Objects
CloudIQ
POD Deployment
Containers

Control Plane
POD
POD Name: metadata.name+<Random#>
Deployment Object POD IP: 178.89.55.34
Scheduler Name POD Label app: corpwebsite
metadata.name

Worker Node 2
API Server
etcd
Calico CNI plugin
Deployment
Object
Containers
Control
Manager
POD
POD Name: metadata.name+<Random#>
POD IP: 172.36.23.25
POD Label app: corpwebsite

template: Worker Node 1


kubectl metadata:
Deployment Spec labels:
CloudIQ
PODs are Grouped by LABELs
Containers
Replicas = 2
Control Plane
POD
POD Name: metadata.name+<Random#>
Deployment Object POD IP: 178.89.55.34
Scheduler Name
metadata.name POD Label app: corpwebsite

Worker Node 2
API Server
etcd

Deployment
Object
Containers
Control
Manager
POD
POD Name: metadata.name+<Random#>
Replicas Set POD IP: 172.36.23.25
Desired = 2
Current =2 POD Label app: corpwebsite
POD Label:
app: corpwebsite Worker Node 1
CloudIQ
POD Network Access

Containers Containers

POD POD
POD IP: 172.36.23.25
POD IP: 178.89.55.34

Worker Node 2 Worker Node 1


Node IP Node IP
Cluster Network

● PODs can talk to each other within Kubernetes Cluster Network

● They are not exposed to External Network or Internet


CloudIQ
POD Service: NodePort

Containers Containers

POD IP: 178.89.55.34 POD IP: 172.36.23.25

POD Label app: corpwebsite POD Label app: corpwebsite

Node IP Node IP

Kubernetes
Traffic Route: Service Object
Internet > Node IP > POD IP NodePort

Azure Load Balancer


CloudIQ
We have to write 2 YAML Files here

POD Deployment YAML File POD Service YAML File

● For Deploying PODs ● For Providing External Access to PODs


● PODs Identified by POD LABEL ● PODs Identified by POD LABEL

How to write?
● Write all in a SINGLE YAML File
● Write 2 separate YAML Files (Recommended)
CloudIQ
YAML Skeleton
kind: Deployment When writing YAML files for Kubernetes, there are four
apiVersion: required fields that must be present.

metadata: APIVersion
name:
labels: Deployment Identification
Kind
label:
Metadata
spec:
replicas: Specifications
strategy: Pod Behaviour
selector:
matchLabels:
label:

template:
metadata:
labels: Pod Identification
label:

spec:
containers:
- name: Container Identification
image:
CloudIQ
POD Deployment
apiVersion: apps/v1
kind: Deployment

metadata: ● Deployment Name


name: deployment-corpwebsite

spec:
selector: ● How many Replicas?
matchLabels:
app: pod-corpwebsite ● Group these Replicas using the
replicas: 2
particular POD LABEL
template:
metadata:
labels:
● POD LABELs
app: pod-corpwebsite
env: dev

spec:
containers:
- name: container-corpwebsite ● Container Specs
image: tanvisinghny/ssl-website
ports:
- containerPort: 80
- containerPort: 443
CloudIQ
Service Deployment
apiVersion: v1
kind: Service

metadata: ● Service Name


name: service-corpwebsite

spec:
type: NodePort ● Service Type: NodePort, Load
selector: Balancer
app: pod-corpwebsite

● nodePort - a static port assigned on


ports:
each the node
- nodePort: 30163
port: 443 ● port - port exposed internally in the
targetPort: 443 cluster
externalIPs:
● targetPort - the container port to
- 165.232.184.39 (workernode1 IP)
send requests to
- 139.59.19.74 (workernode2 IP)

● Worker Node IPS where the PODs are


running
ports: CloudIQ
- nodePort: 30163
port: 443
targetPort: 443 https://www.krishnaazure.xyz:444
139.59.19.74

nodePort: 30000 - 32767

Containers Containers Containers

port: 443 port: 443 port: 443

nodePort: 30163 nodePort: 32000 nodePort: 32005

165.232.184.39 (443)

https://www.cloudiq.in targetPort: 443

https://www.krishnaazure.xyz targetPort: 443


CloudIQ
POD Resource Limits
Kubernetes doesn’t provide default resource limits
out-of-the-box

Limits = Max amount of a resource (RAM or CPU)

Requests = Min guaranteed amount of a resource (RAM or


CPU)

resources: resources:
limits: limits:
memory: 200Mi memory: 2G
cpu: 300m cpu: 3
requests: requests: CPU represents computing processing time, measured in
memory: 100Mi memory: 1G
cpu: 100m cores.
cpu: 1
● You can use millicores (m) to represent smaller
amounts than a core (e.g., 500m would be half a
Memory is measured in Kubernetes in bytes:
core)
You can use, E, P, T, G, M, k to represent Exabyte, Petabyte,
Terabyte, Gigabyte, Megabyte and kilobyte ● The minimum amount is 1m

You can define Mebibytes using Mi, as well as the rest as Ei, Pi, ● A Node might have more than one core available, so
Ti (e.g., 500Mi) requesting CPU > 1 is possible
CloudIQ
YAMl File with Resource Limits
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-corpwebsite
spec:
selector:
matchLabels:
app: pod-corpwebsite
replicas: 2
template:
metadata:
labels:
app: pod-corpwebsite
env: dev
spec:
containers:
- name: container-corpwebsite
image: tanvisinghny/ssl-website
ports:
- containerPort: 80
- containerPort: 443
resources:
limits:
memory: 200Mi
cpu: 300m
requests:
memory: 100Mi
cpu: 100m
CloudIQ
POD Resource Limits
Verifying Resource Limits set

kubectl describe deployment <deployment-name>

kubectl describe deployment <pod-name>

Verifying Resource Limits inside the pod

Go inside POD:

kubectl exec -it <pod-name> -n <namespace> -- /bin/bash

Get CPU, Memory Stats

cd /sys/fs/cgroup/

Find various statistics based on files described in that


folder
CloudIQ
Built-in Kubernetes Metrics
Install Metrics-Server Components

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

Edit the file and ADD the metrics:

sudo nano components.yaml

Once done, apply the changes

kubectl apply -f components.yaml


CloudIQ
Verify if Metrics-Server is Running
linuxadmin@master:~$ kubectl get pods -n kube-system

NAME READY STATUS RESTARTS AGE

calico-kube-controllers-6c99c8747f-tgc6w 1/1 Running 0 36h

calico-node-dgjww 1/1 Running 0 36h

calico-node-hzzbg 1/1 Running 0 36h

—--

metrics-server-f94d65847-vwq2s 1/1 Running 0 27m


CloudIQ
Test Metrics Server Installation
Display the resource utilization for each node in your cluster, including CPU and memory usage

linuxadmin@master:~$ kubectl top nodes

NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%

master 138m 6% 2235Mi 58%

node1 49m 2% 1636Mi 42%

node2 40m 2% 1601Mi 41%


CloudIQ
Test Metrics Server Installation
View pods resource utilization of your current namespace

linuxadmin@master:~$ kubectl top pod

NAME CPU(cores) MEMORY(bytes)

deployment-corpwebsite-7675c48cc6-6zn5d 1m 7Mi

deployment-corpwebsite-7675c48cc6-rl4sh 1m 7Mi
CloudIQ
Test Metrics Server Installation
view pods resource utilization of your current namespace

linuxadmin@master:~$ kubectl top pod

NAME CPU(cores) MEMORY(bytes)

deployment-corpwebsite-7675c48cc6-6zn5d 1m 7Mi

deployment-corpwebsite-7675c48cc6-rl4sh 1m 7Mi

You might also like