# Create Pod
kubectl create -f 02-pod-definition.yml
[or]
kubectl apply -f 02-pod-definition.yml
# List Pods
kubectl get pods
apiVersion: v1
kind: Service
metadata:
name: myapp-pod-nodeport-service # Name of the Service
spec:
type: NodePort
selector:
# Loadbalance traffic across Pods matching this label selector
app: myapp
# Accept traffic sent to port 80
ports:
- name: http
port: 80 # Service Port
targetPort: 80 # Container Port
nodePort: 31231 # NodePort
# Create Service
kubectl apply -f 03-pod-nodeport-service.yml
# List Service
kubectl get svc
# Get Public IP
kubectl get nodes -o wide
# Access Application
http://<WorkerNode-Public-IP>:<NodePort>
http://<WorkerNode-Public-IP>:31231