Monday 20 July 2020

Kubernetes: Port Forwarding: Access Pods

Port Forwarding is the simple way to talk to Pod port. Port forwarding is an easy and effective way to test the application running in Pod.

 

portForwarding.yml

apiVersion: v1
kind: Pod
metadata:
  name: employee-service
  labels:
    app: employee-service
    author: krishna
    serviceType: webservice
spec:
  containers:
    - name: employee-service-container
      image: jboss/wildfly

Create a Pod by executing the below command.

$kubectl create -f portForwarding.yml 
pod/employee-service created

Make sure that the Pod is running.

$kubectl get pods
NAME               READY   STATUS    RESTARTS   AGE
employee-service   1/1     Running   0          19s

By default ‘jboss/wildfly’ server runs on port 8080, lets access the application running in a Pod by executing below command.

kubectl port-forward pod/employee-service 5678:8080

 

Above command forward your machine’s local port 5678 to port 8080 of your employee-service pod.


$kubectl port-forward pod/employee-service 5678:8080
Forwarding from 127.0.0.1:5678 -> 8080
Forwarding from [::1]:5678 -> 8080

Open the url ‘http://localhost:5678/’ in the browser, you can see that ‘WildFly’ server is up and running.


You can delete the Pod, by executing the below command.

kubectl delete pod employee-service

$kubectl delete pod employee-service
pod "employee-service" deleted



Previous                                                    Next                                                    Home

No comments:

Post a Comment