Category : Kubernetes | Sub Category : Kubernetes With Java | By Prasad Bonam Last updated: 2023-11-17 08:23:58 Viewed : 524
A Pod is the smallest deployable unit in Kubernetes, representing a single instance of a running process. It can contain one or more containers.
yamlapiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: nginx-container
image: nginx
Explanation:
A Service exposes a set of Pods as a network service. It allows other applications to discover and communicate with the Pods.
yamlapiVersion: v1
kind: Service
metadata:
name: example-service
spec:
selector:
app: example-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
Explanation:
A Namespace provides a way to divide cluster resources between multiple users or teams.
yamlapiVersion: v1
kind: Namespace
metadata:
name: example-namespace
Explanation:
A Deployment manages the deployment and scaling of Pods, allowing declarative updates to applications.
yamlapiVersion: apps/v1
kind: Deployment
metadata:
name: example-deployment
spec:
replicas: 3
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: nginx-container
image: nginx
Explanation:
A ReplicaSet ensures a specified number of replicas of a Pod are running.
yamlapiVersion: apps/v1
kind: ReplicaSet
metadata:
name: example-replicaset
spec:
replicas: 2
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: nginx-container
image: nginx
Explanation:
A ConfigMap allows you to decouple configuration artifacts from the container image.
yamlapiVersion: v1
kind: ConfigMap
metadata:
name: example-configmap
data:
key1: value1
key2: value2
Explanation:
A Secret stores sensitive information, such as passwords or API keys, in a Base64-encoded format.
yamlapiVersion: v1
kind: Secret
metadata:
name: example-secret
type: Opaque
data:
username: <base64-encoded-username>
password: <base64-encoded-password>
Explanation:
A Volume is a directory that is accessible to containers in a Pod, providing a way to persist data.
yamlapiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: nginx-container
image: nginx
volumeMounts:
- name: example-volume
mountPath: /usr/share/nginx/html
volumes:
- name: example-volume
emptyDir: {}
Explanation:
An Ingress provides HTTP and HTTPS routing to services based on rules, enabling external access to services in a cluster.
yamlapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
Explanation:
These examples cover some of the fundamental Kubernetes resources and how they are configured. You can customize these examples based on your specific application requirements.