Posted on January 18, 2023
Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications. To deploy an application with Kubernetes, you'll need to create a Kubernetes "manifest" file, which defines the desired state of your application and its resources. To enable Kubernetes from Docker Desktop, follow these steps: Please ensure your system meets the requirement to run Kubernetes on the Docker desktop. OR use Azure Kubernetes Service Follow another article for (HOW TO CREATE AZURE KUBERNETES SERVICE (AKS?) Here is an example of a Kubernetes manifest file for a simple web application that runs in a Docker container: This manifest file defines a Deployment named "my-web-app" that will run 3 replicas of a container based on the "my-web-app:latest" image, and that container will listen on port 80. To deploy this application to a Kubernetes cluster, you can use the kubectl command-line tool and run the following command: This command will create the deployment and the necessary ReplicaSet (Learn more about in my other blogs ) and Pods in the cluster. You can also create a service to expose the application on the network using the following yaml file: This service will create a load-balancer that will route the traffic to the pods and expose the service on port 80. Keep in mind that this is just a simple example and you should adjust the configuration according to your needs. To deploy an application with Kubernetes, you need to create a manifest file that defines the desired state of your application and its resources. The manifest file should include information such as the number of replicas, the container image, and the ports that the application will use. You can use the kubectl command-line tool to deploy the application to a Kubernetes cluster by running the command "kubectl apply -f my-web-app.yaml". Additionally, you can create a service to expose the application on the network by creating a service yaml file and applying it to the cluster using "kubectl apply -f my-web-app-service.yaml" which will create a load-balancer that routes the traffic to the pods.Enable Kubernetes from Docker Desktop
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-web-app
spec:
replicas: 3
selector:
matchLabels:
app: my-web-app
template:
metadata:
labels:
app: my-web-app
spec:
containers:
- name: my-web-app
image: my-web-app:latest
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: my-web-app
spec:
selector:
app: my-web-app
ports:
- name: http
port: 80
targetPort: 80
type: LoadBalancer
Summary