Projects:Kubernetes: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 610: | Regel 610: | ||
As you can see, our <code>nginx-service</code> service is now up and it got external port 31106. Indeed, when we go to <code>http://<IP>:31106/</code> (replacing <IP> with the IP of any of our nodes) we can see the page again! Also, when we <code>kubectl delete pod ...</code> arbitrary pods within the deployment, they are restarted automatically, and accesses to the external IP/port keep working as long as at least one pod is <code>Running</code>. | As you can see, our <code>nginx-service</code> service is now up and it got external port 31106. Indeed, when we go to <code>http://<IP>:31106/</code> (replacing <IP> with the IP of any of our nodes) we can see the page again! Also, when we <code>kubectl delete pod ...</code> arbitrary pods within the deployment, they are restarted automatically, and accesses to the external IP/port keep working as long as at least one pod is <code>Running</code>. | ||
There is an alternative way to make a Service externally reachable that can be convenient: you can set an <b>externalIP</b> on a <code>ClusterIP</code> type Service and any Node with that IP will listen on the indicated Service Port -- but that comes with a big fat warning: it introduces a single point of failure into your Service, as it will be unreachable if that Node is down! Yet, it can be very convenient especially for bare-metal clusters, so I'll show you how to do it: | |||
<pre> | |||
$ cat service-externalip.yaml | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: nginx-service-externalip | |||
spec: | |||
selector: | |||
app: nginx | |||
ports: | |||
- name: nginx | |||
port: 80 | |||
protocol: TCP | |||
type: ClusterIP | |||
externalIPs: | |||
- "145.131.6.177" # Replace this with one of your node's IPs, of course! | |||
$ kubectl apply -f service-externalip.yaml | |||
$ kubectl get services | |||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |||
kubernetes ClusterIP 10.16.0.1 <none> 443/TCP 19d | |||
nginx-service NodePort 10.16.247.178 <none> 80:31106/TCP 11d | |||
nginx-service-externalip ClusterIP 10.16.165.143 145.131.6.177 80/TCP 3s | |||
</pre> | |||
Sure enough, if you visit your external IP on port 80, you should see the same page served by Nginx appear! | |||
== Accessing a Deployment using an Ingress == | == Accessing a Deployment using an Ingress == |