Kubernetes Objects-Pod in detail

apiVersion: v1
kind: Pod
metadata:
name: string
namaspace: string
labels:
- name: string
annotations:
- name: string
spec:
containers:
- name: string
images: string
imagePullPolice: [Always | Never | IfNotPresent]
command: [string]
args: [string]
workingDir: string
volumeMounts:
- name: string
mountPath: string
readOnly: boolean
ports:
- name: string
containerPort: int
hostPort: int
protocol: string
env:
- name: string
value: string
resources:
limits:
cpu: string
memory: string
requests:
cpu: string
memory: string
livenessProbe:
exec:
command: [string]
httpGet:
path: string
port: int
host: string
scheme: string
httpHeaders:
- name: string
value: string
tcpSocket:
port: int
initialDelaySeconds: number
timeoutSeconds: number
periodSeconds: number
successThreshold: 0
failureThreshold: 0
securityContext:
privileged: false
restartPolicy: [Always | Never | OnFailure]
nodeSelector: object
imagePullSecrets:
- name: string
hostNetwork: false
volumes:
- name: string
emptyDir: {}
hostPath:
path: string
secret:
secretName: string
items:
- key: string
path: string
configMap:
name: string
items:
- key: string
path: string

Basic usage of Pod

Pod commands Here

Static pod

apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
name: static-web
spec:
containers:
- name: static-web
image: nginx
ports:
- name: web
containerPort: 80

Pod container sharing volume

apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: tomcat
image: tomcat
ports:
- containerPort: 8080
volumeMounts:
- name: app-logs
mountPath: /usr/local/tomcat/logs
- name: pankajapp
image: pankajapp
command: ["sh","-c","tailf /logs/catalina*.log"]
volumeMounts:
- name: app-logs
mountPath: /logs
volumes:
- name: app-logs
emptuDir: {}
kubectl logs <pod_name> -c <container_name>kubectl exec -it <pod_name> -c <container_name> – tail /usr/local/tomcat/logs/catalina.xx.log

Pod configuration management

ConfigMap: Configuration management of container applications

Scenes that can be used:Created in the container as an environmental variable. 
Set the startup parameters of the startup command of the container (need to be set as environment variables).
Mount a volume in the form of a file or directory within the container.
In kubernetes, ConfigMap is stored in the form of one or more key:values for application use. The value of a variable (for example: apploglevel=info) or the content of a full configuration file (for example: server.xml= <?xml…>) may be described.
You can use the yaml configuration file to create a ConfigMap, or use the kubectl create configmap order.

Create ConfigMap

Via yaml file

apiVersion: v1
kind: ConfigMap
metadata:
name: cm-appvars
data:
apploglevel: info
appdatadir: /var/data
Common commandskubectl create -f cm-appvars.yamlkubectl get configmapkubectl describe configmap cm-appvarskubectl get configmap cm-appvars -o yaml

Via kubectl command line

To create a configmap by creating kubectl, use the -from-file or -from-literal parameters to specify the information, and you can specify multiple parameters on a line.1) You can create a ConfigMap from a file with the -from-file parameter, define a key name, or create a ConfigMap that includes several keys on a single command line.Kubectl generates the NAME config map —from-file=[key=]source —from-file=[key=]source2) Build from a directory with parameter -from-file. The name of each configuration file in the directory is set as the key and the value is set to the content of the file.Kubectl produces the Term configmap —from-file=config-files-dir3) Create from text through -from-literal, and create the required key=value directly as the ConfigMap content.Kubectl generates a NAME config map —from-literal=key1=value1 —from-literal=key2=value2=value2=value1=value1In container applications, there are two ways of using ConfigMap:Get the content from environment variables in the ConfigMap. 
By volume mounting, install the content in the ConfigMap as a file or directory within the container.

By way of environment variables

apiVersion: v1
kind: ConfigMap
metadata:
name: cm-appvars
data:
apploglevel: info
appdatadir: /var/data
apiVersion: v1
kind: Pod
metadata:
name: cm-test-pod
spec:
containers:
- name: cm-test
image: pankajapp
command: ["/bin/sh","-c","env|grep APP"]
env:
- name: APPLOGLEVEL
valueFrom:
configMapKeyRef:
name: cm-appvars
key: apploglevel
- name: APPDATADIR
valueFrom:
configMapKeyRef:
name: cm-appvars
key: appdatadir
kubectl create -f cm-test-pod.yamlkubectl get pods — show-allkubectl logs cm-test-podRestrictions on the usage of ConfigMap 
1. Before Pod, ConfigMap must be developed,
2.It is also possible to describe ConfigMap as belonging to Namespace. It can be referenced only by Pods in the same namespace.
3.Kubelet is only supported by Pods that can be handled by the ConfigMap API Server. Unable to reference the Static Pod.
4.The container can only be installed as a directory when the Pod mounts the ConfigMap, and can not be mounted as a file.

Pod life cycle

Pod status

Pod restart strategy

RC and DaemonSet: Always must be set, and the container must be running on an ongoing basis. 
Job: OnFailure or Never, to ensure that after execution the container does not restart.
Kubelet: Restart a Pod when it crashes, irrespective of the importance of the RestartPolicy environment, and the Pod does not carry out a health check.

Common state transition scenarios

ProbeLiveness 
Used to determine whether the container is still alive (running state).
Kubelet will destroy the container and deal with it according to the container’s restart strategy if the LivenessProbe probe detects that the container is unsafe.
If the container does not contain the LivenessProbe probe, kubelet considers the return value of the probe to always be “success”.
ReadinessProbe For Preparation
It is used to determine if the container is initiated (read state) and the request can be accepted.
The status of the Pod will be changed if the ReadnessProbe probe fails. The Endpoint Controller will delete from the Endpoint of the Service the Endpoint containing the Pod where the container is placed.

--

--

--

Database/System Administrator | DevOPS | Cloud Specialist | DevOPS

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why do you need to understand hardware to make better software?

Announcement of Move Protocol launches on COSOSWAP NFT Launchpad (0609)

How good metadata supports data pipelines

From Node.js to Go

Google Cloud Platform : Tips & Tricks for python

How streaming flow works in Gaana ?

Status Report Vol. 10

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pankaj kushwaha

Pankaj kushwaha

Database/System Administrator | DevOPS | Cloud Specialist | DevOPS

More from Medium

Kubernetes PoC — Ubuntu 20.04

Docker and The Rise of Containerization

Building containers without Docker

Run Argo CD using operator on Kind