In this post, I am going to explain how to expose a Pod using
NodePort service type
It is a very basic way to expose a service. NodePort service opens a specific port on all the nodes and any request comes to this port will be forwarded to actual service.
Step 1: Define a deployment definition file.
nodePortDemo.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: notification-service-deployment
labels:
app: notification-service-deployment
author: krishna
serviceType: webservice
spec:
template:
metadata:
name: notification-service
labels:
app: notification-service
author: krishna
serviceType: webservice
spec:
containers:
- name: notification-service-container
image: jboss/wildfly
replicas: 1
selector:
matchLabels:
app: notification-service
Step 2: Create a deployment by executing the below command.
$kubectl create -f nodePortDemo.yml
deployment.apps/notification-service-deployment created
Step 3: Expose the
kubectl expose deployment notification-service-deployment --port=8080 --type=NodePort
$kubectl expose deployment notification-service-deployment --port=8080 --type=NodePort
service/notification-service-deployment exposed
Step 4: Query all the services by executing the below commands.
$kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 31d
notification-service-deployment NodePort 10.102.16.86 <none> 8080:30054/TCP 11s
Step 5: Execute below command to open wildfly application in the browser.
minikube service notification-service-deployment
$minikube service notification-service-deployment
|-----------|---------------------------------|-------------|-----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|---------------------------------|-------------|-----------------------------|
| default | notification-service-deployment | 8080 | http://192.168.99.100:30054 |
|-----------|---------------------------------|-------------|-----------------------------|
🎉 Opening service default/notification-service-deployment in default browser...

No comments:
Post a Comment