Azure / aksArc

# Welcome to the Azure Kubernetes Service on Azure Stack HCI repo This is where the AKS-HCI team will track features and issues with AKS-HCI. We will monitor this repo in order to engage with our community and discuss questions, customer scenarios, or feature requests. Checkout our projects tab to see the roadmap for AKS-HCI!
MIT License
109 stars 45 forks source link

[BUG] LoadBalancerIP does not work with servicetype=LoadBalancer #283

Closed baziwane closed 1 year ago

baziwane commented 1 year ago

In AKS hybrid, when a user specifies the LoadBalancerIP for a service as described in the Kubernetes service spec, this does not work.

Workaround For now, we recommend using ExternalIPs as we work on a permanent fix in an upcoming release. You need to make sure the IP address is within the range of the VIP pool you used during cluster creation. Below is an example of how you would assign a static IP address to a service in AKS hybrid.

Step 1 - Create an application deployment. In this example I will use nginx.

kubectl create deployment nginx --image=nginx

Step 2 - Create a service of type=LoadBalancer and set the value externalIPs with the static IP address that you want to use to access the service.
Note: You cannot specify an IP address that's outside the range that was when you created the cluster network.

Save the following example in a file named nginx-service.yaml

apiVersion: v1
kind: Service
metadata:
 name: nginx
 annotations:
spec:
 type: LoadBalancer
 ports:
  - port: 80
  protocol: TCP
  targetPort: 80
 selector:
  app: nginx
 externalIPs:
 - 192.168.248.15 # this IP address should be in the same range as your VIP pool 

Open a terminal and run kubectl apply to create the service

kubectl apply -f nginx-service.yaml

You can verify that the externalIP has been assigned to the service by running the following command:

kubectl get svc

NAME     TYPE      CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
kubernetes  ClusterIP   10.96.0.1    <none>     443/TCP    5d18h
nginx    LoadBalancer  10.120.110.180  192.168.248.15  80:30304/TCP  7s

Step 3 - Test the service

Run curl to verify that the service is reachable:

curl 192.168.248.15
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>