Pod is a group of containers that are deployed together on the same host. For single process deployment artifact, we can generally think “pod” as a “container” to accurately understand the concept. Pods operate at one level higher than individual containers.
localhost with co-located container PORT can be used to communicateapiVersion: v1 #K8s API version (mandatory)
kind: Pod #K8s object type. (mandatory) Note: Rather use Deployment and StatefulSet for Production deployment
metadata:
name: hello-world #Name of the Pod (mandatory) This will be displayed via `kubectl get pods`
labels: #Custom open ended labels/tagging. Note: While defining Service these will be used as selectors
app: hello-world
owner: digital-marketing
tire: backend
key1: value1
spec:
containers:
- name: hello-world-cntr #Name of the Container inside the Pod
image: library/hello-world #Docker Image
resources: #Resources configuration for Docker Image Container
limits:
memory: "200Mi"
cpu: "200m"
requests:
memory: "100Mi"
cpu: "100m"
requests and limitkubectl get pods or even try kckubectl get pods -o widekubectl describe pods/<pod_name> (Events , Resource alocated , Laster Run status etc.) - Get last status kubectl get pods/<pod_name> -o go-template=""apiVersion: ..
kind: ..
metadata:
name: ..
labels:
app: hello-world
owner: digital-marketing
equality-based . Available in type Service , Deployment , ReplicaSet , Job and DeamonSet
...
spec:
selector:
app: hello-world
...
set-based . Available in type Deployment , ReplicaSet , Job and DeamonSet
...
spec:
selector:
matchLabels:
app: hello-world #Equality based
matchExpressions: #Set based
- {key: tier, operator: In, values: [backend]}
- {key: env, operator: NotIn, values: [dev]}
...
apiVersion: ...
kind: ...
metadata:
name: ...
annotations:
service.beta.kubernetes.io/decc-load-balancer-https-backend-ports: "443"
service.beta.kubernetes.io/decc-load-balancer-https-redirection-ports: "80:443"
spec:
...
Service is an abstraction (across namespace) which defines a logical set of Pods and a policy by which to access them.
Service provides traffic Proxying , Network Address Translation and NameService via K8s kube-proxy and CoreDNS
What it enables is to Traffic to flow through the External LoadBalancer/Internet to K8s cluster to the Container running the Processes

apiVersion: v1
kind: Service
metadata:
name: hello-world-service #Name of the service.
spec:
type: NodePort #Will discuss this below.
selector:
app: hello-world #App names from where the ClusterIPs will be pulled
ports:
- protocol: TCP
port: 80 #Service Port
targetPort: 9376 #Target Pod's PORT
nodePort: 30620 #Will discuss this below. Nodes port from where kube-proxy can forward the traffic
Service' clusterIP:port to Pod clusterIPs:targetPorthello-world-service resolving to it’s own Service' clusterIPnodePort traffic to be forwarded to Service clusterIP:port(Default) Exposes the Service on a cluster-internal IP. This makes the Service only reachable from within the cluster via just {servicename} or {servicename}.{namespace}.svc.cluster.local
port to a targetPort. By default and for convenience, the targetPort is set to the same value as the port field.Exposes the Service on each Node’s IP at a static port (the NodePort). Service can be accessed via <NodeIP>:<NodePort> from Outside.
Exposes the Service externally using a cloud provider’s Load Balancer.
LoadBalancer implementation to support it
Maps the Service to the contents of the externalName field (e.g. foo.bar.example.com), by returning a CNAME record
common-db-service as my.database.example.com , rather than Proxing
apiVersion: v1
kind: Service
metadata:
name: common-db-service
namespace: prod
spec:
type: ExternalName
externalName: my.database.example.com
yaml definition.
kind: ConfigMap # can be Secrets
apiVersion: v1
metadata:
name: hello-world-cm # Secrets name would be hello-world-secrets
labels:
app: hello-world
data:
username: admin #In ccase it's Secrets value will be YWRtaW4= (Base64 of admin is YWRtaW4=)
...
Define a container environment variable with data from a single ConfigMap/Secret
apiVersion: v1
kind: Pod
metadata:
name: hello-world
spec:
containers:
- name: hello-world-cntr
...
env:
- name: USERNAME
valueFrom:
configMapKeyRef: # For Secrets use secretKeyRef
name: hello-world-cm # Can be hello-world-secrets
key: username
...
Mount as a Volume and read from it
apiVersion: v1
kind: Pod
metadata:
name: hello-world
spec:
containers:
- name: hello-world-cntr
...
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: hello-world-cm