I ran a local cluster according to its official doc here . I followed the steps and it worked properly until I set a replica and tried to exposed it. I mean:
./kubectl expose rc nginx --port=80
the output is this:
NAME LABELS SELECTOR IP(S) PORT(S)
nginx run=nginx run=nginx 80/TCP
When I tried another time it sayed the the same service is running. How can I figure out the IP?
kubectl get service/servicename -o jsonpath='{.spec.clusterIP}'
kubectl get svc <your-service> -o yaml | grep ip
The IP should be the external IP of your master-node. If you're running locally it should be localhost or your VM.
Of course with the given port added.
127.0.0.1:80
for example.
PS: Be sure you have containers/pods running already by running:
kubectl get pods
If this doesn't work, I would suggest proxying it, for test-purposes at least.
There are a couple of ways to do this:
kubectl get svc <service-name> -o yaml | grep clusterIP
or for example:
kubectl describe svc <service-name> | grep IP
For convenient reference:
curl `kc describe svc nginx | grep IP | awk '{print $2}'`
And as a kurl
bash function...
## for curling services by name...
kurl() {
name=$1
path=$2
add=`kc describe svc $name | grep IP | awk '{print $2}'`$path
# echo "hitting $add"
curl $add
}
# kurl nginx :8080/some/path/you/want
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.