Resources: request and limit
| Resource type | Description | Base unit |
|---|---|---|
| cpu | Compute processing | cpu (core) |
| memory | RAM | Bytes |
| ephemeral-storage | Local ephemeral | storage Bytes |
| hugepages-<size> | Huge pages | (Linux only) Bytes |
### Add resource limits and requests in pod
resources: request: cpu: “500m” memory:“128mi” limits: cpu: “1” memory:“2”
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
labels:
app: sample
environment: production
spec:
containers:
- name: sample-container
image: nginx:latest
ports:
- containerPort: 80
resources:
request:
cpu: "500m"
memory:"128mi"
limits:
cpu: "1"
memory:"2"
- name: init-sample
image: busybox:latest
command: ["sh", "-c", "echo Initializing... && sleep 10"]
/bin/bash -c
QOS
Guaranteed:
- every container will have
limits == request - give request and limit we be having limits values
resources:
request:
cpu: "2"
memory:"4"
limits:
cpu: "2"
memory:"4"
Burstable:
- it required resources request and limit need to mention
- every container will have
limits > request
resources:
request:
cpu: "500m"
memory:"1"
limits:
cpu: "2"
memory:"4"
Best-Effort
- no resource request and limits required
- it will automatically managed by K8s
workloads in k8s
- pod : single unit which will run the application as container
- replica-controller: it will create no of pods based replicas count
- replicaset: keep N identical pods running (disered state)
- Deployment: stateless apps (runing continously and deploy, upgrade and rollback will be suppourted) (webapps,)
- statefullset: run apps in statefull (databases, kafka)
- stable name and storage
- DaemonSet: run one pod per node (logs and monitoring)
- job : run to complte (used for run some automation scrpits and migrations)
- cronjob: scheduled jobs ( backups, cleanup, generate reports) sample cron expersion
kubectl cmds for pod:
#### Basic cmds
kubectl get pods # get all pods in default namespace
kubectl get pods -n <namespace>
kubectl get pods -n kube-system # namespace is kube-system
kubectl get pods -A # To get all pods from all namespaces
kubectl get pods nopcommerceteam # see details specific pod
kubectl get pods -w # watch pods
kubectl get pods -o wide # details of pods
kubectl apply -f filename.yaml # create pod by yaml file
kubectl run --name=nginx --image=nignx:latest
#### debug:
kubectl logs <podname> -n <namespace> # when container is created
kubectl describe <podname> -n <namespace> # give details for pods
kubectl logs -f <podname> -n <namespace>
kubectl logs <podname> -c <conatinername> -n <namespace> # Get logs for specific container.
## Delete cmds:
kubectl delete -f filename.yaml # to delete pod by using yaml file
kuebctl delete pod <podname> -n <namespace> # delete pod by pod name
---
apiVersion: v1
kind: Pod
metadata:
name: nopcommerceteam
labels:
app: nopcommerce
environment: production
spec:
containers:
- name: nopcommerce-container1
image: httpd:latest
ports:
- containerPort: 5000
resources:
limits:
memory: "512Mi"
cpu: "500m"
requests:
memory: "256Mi"
cpu: "250m"
---
apiVersion: v1
kind: Pod
metadata:
name: apache2
labels:
app: apache2
environment: production
spec:
containers:
- name: apache2
image: httpd:latest
ports:
- containerPort: 80
resources:
limits:
memory: "512Mi"
cpu: "500m"
requests:
memory: "256Mi"
cpu: "250m"
Task:
- create different pod and try above QOS (resources)
- try all above k8s commnads
