- kubernetes.io > Concepts > Services, Load Balancing, and Networking > Service
kubectl create service clusterip app2 --tcp=80 --dry-run -o yaml
kubectl create service nodeport app2 --tcp=80 --node-port=32000 --dry-run -o yaml
kubectl create service loadbalancer app2 --tcp=80 --dry-run -o yaml
Or
kubectl expose pod nginx --port=80 [--type=ClusterIP] --dry-run -o yaml
kubectl expose deployment nginx --port=80 --type=NodePort --dry-run -o yaml
kubectl expose rc nginx --port=80 --type=LoadBalancer --dry-run -o yaml
Using kubectl create service
does not create the EndPoints for a NodePort service, instead use kubectl expose
and add the nodePort: PORT
to Service.spec.ports[N].nodePort
.
kubectl get services
clusterIP=$(kubectl get service app2 -o jsonpath='{$.spec.clusterIP}')
kubectl run busybox --image=busybox -it --rm --restart=Never -- sh -c "wget -q -O- http://${clusterIP}:${ServiceIP} | head -10"
curl -s http://${NodeIP}:${ServiceIP} | head -10
lbPort=$(kubectl get service app2 -o jsonpath='{$.spec.ports[0].nodePort}')
curl -s http://localhost${lbPort | port} | head -10
From: kubernetes.io > Concepts > Services, Load Balancing, and Networking > Service
Create a Service with kubectl
kubectl expose deployment/nginx --port=80 --type=NodePort
kubectl get services
kubectl get service nginx -o yaml
Get the port from Service.spec.ports.nodePort
to open http://<publicIP>:<nodePort>/
List of Ingress Controllers: