Category : Kubernetes | Sub Category : Kubernetes With Java | By Prasad Bonam Last updated: 2023-11-21 10:58:31 Viewed : 217
Deploying using standalone manifests involves creating separate YAML files for different Kubernetes resources (such as Deployments, Services, ConfigMaps, etc.) and applying these manifests to a Kubernetes cluster using kubectl
. Below is a step-by-step guide to deploying a simple application using standalone manifests:
Create a file named deployment.yaml
with the following content:
yamlapiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: nginx:latest
ports:
- containerPort: 80
This Deployment manifest defines a simple NGINX deployment with three replicas.
Create a file named service.yaml
with the following content:
yamlapiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
This Service manifest defines a LoadBalancer service for exposing the NGINX deployment.
Run the following commands to apply the deployment and service manifests to the Kubernetes cluster:
bashkubectl apply -f deployment.yaml kubectl apply -f service.yaml
This deploys the NGINX application and exposes it through the LoadBalancer service.
You can monitor the status of the deployment using the following command:
bashkubectl get deployments
This should show information about your my-app-deployment
with the desired and current replicas.
You can check the status of the service using:
bashkubectl get services
This should show information about your my-app-service
including the external IP if you are using a cloud provider.
If using Minikube, you can access the service using:
bashminikube service my-app-service
For cloud providers, you might need to wait for the external IP to be assigned to the service and then access the application using that IP.
To delete the deployed resources, use the following commands:
bashkubectl delete deployment my-app-deployment kubectl delete service my-app-service
This removes the NGINX deployment and service from the cluster.
Deploying using standalone manifests is a common practice in Kubernetes and allows you to manage your applications resources in a modular and version-controlled way. As your application grows, you can create additional manifests for other resources such as ConfigMaps, Secrets, PersistentVolumes, etc.