Kubernetes Manifest Yaml files
Kubernetes is an orchestration-platform, which is to manage containers.
When working with Kubernetes (K8s), you can interact with it using two primary modes: imperative mode and declarative mode.
imperative mode means to run the commands, declarative mode k8s manifest yaml files.
1.To create a Pod:
apiVersion: v1
kind: Pod
metadata:
name: your_app_name
labels:
name: your_app_name_pod
spec:
containers:
- name: your_contaianer_name
image: docker_image_name
ports:
- containerPort: 8080
2.Service: Is to Expose your application outside the cluster.To expose outside the cluster then we have three type that are ClusterIP,NodePort,Load Balancer.
ClusterIP
is one of the service types used to expose applications within the cluster. When you create a Service of type ClusterIP
, Kubernetes assigns a stable virtual IP address (ClusterIP) to the Service. This IP address is accessible only within the cluster and is not exposed externally.
Node Port: we can expose outside the cluster
apiVersion: v1
kind: Service
metadata:
name: your_app_name
labels:
name: your_app_name_svc
spec:
selector:
app: your_app_name # Select pods with the 'app' label set to 'your_app_name
type: NodePort # Exposes the service on a random port (NodePort) on all nodes in the cluster
ports:
- protocol: TCP
port: 80 # Port on the service through which it will be accessed
targetPort: 9090 # Port on the pods to forward traffic to
nodePort: 30002 # Port on the host (NodePort) through which the service will be accessible externally
3.ReplicationController
It creates replicas so that when a depodgrades or fails it will take care of createing pods
apiVersion: app/V1
kind: ReplicationController
metadata:
name: my_app_name
spec:
replicas: 4 #enter the number to maintain the replicas
selector:
app: my_app_rc
templates:
metadata:
labels:
app: my_app_rc
spec:
containers:
- name: my_ontainer_name
image: image-name
ports:
- containerPort: 9000
-