This post will show you how to deploy the application and publish it on a Kubernetes cluster and make it available over the internet.
Expose
The concept of making a deployed application available over the internet is called expose. We can use either the kubectl expose command or using a YAML by creating a service. In this post, I will use a YAML file.
Create Deployment
First, let me deploy my application using a YAML file, as shown below. The app has port 80 available for web requests.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx env: "dev" spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
I will go ahead and deploy the app using the following command.
kubectl apply -f deployservice.yaml
Once the application is deployed, I will go ahead and create a service.
Create a Service
The following YAML file will expose the above application on port 80 and make it available using the cluster LoadBalancer IP address.
apiVersion: v1 kind: Service metadata: name: nginx labels: run: nginx spec: ports: - port: 80 protocol: TCP selector: app: nginx type: LoadBalancer
To deploy the service I will use the following command.
kubectl apply -f deployservice.yaml
To check the service IP address, I will run the following command, and note down the EXTERNAL-IP details.
kubectl get service nginx