apache / cloudstack-kubernetes-provider

Apache Cloudstack Kubernetes Provider
https://cloudstack.apache.org/
Apache License 2.0
40 stars 23 forks source link

Support static public ip address as a Load balancer IP #51

Open kiranchavala opened 1 year ago

kiranchavala commented 1 year ago

ISSUE TYPE

COMPONENT NAME

Component: Kubernetes/Networking

CLOUDSTACK VERSION

Cloudstack 4.18

SUMMARY

Support static public ip address as a Load balancer IP

STEPS TO REPRODUCE

  1. Deploy Kubernetes cluster on Cloudstack

  2. Create a deployment for example a nginx deployment


apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
  1. Expose the deployment as a loadbalancer service

kubectl expose deploy/nginx-deployment --port=80 --type=LoadBalancer

  1. Cloudstack then randomly allocated a public ip as external ip
❯ kubectl get svc nginx-deployment
NAME               TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
nginx-deployment   LoadBalancer   10.109.88.98   10.0.54.83    80:32739/TCP   4m24s
  1. Suppose a user wants a specific public ip as a loadbalancer ip

Currently it's not possible even if we manually edit the service.yaml, cloudstack again allocates a random public ip

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2023-07-25T04:31:03Z"
  finalizers:
  - service.kubernetes.io/load-balancer-cleanup
  name: nginx-deployment
  namespace: default
  resourceVersion: "995303"
  uid: 224691be-fa86-4b07-938c-c86d948b99fb
spec:
  allocateLoadBalancerNodePorts: true
  clusterIP: 10.109.88.98
  clusterIPs:
  - 10.109.88.98
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - nodePort: 32739
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  sessionAffinity: None
  type: LoadBalancer
status:
apiVersion: v1
  loadBalancer:
apiVersion: v1
    ingress:
    - ip: 10.0.54.83

EXPECTED RESULTS

Cloudstack should allocate the specified public ip address

ACTUAL RESULTS

Clodudstack is allocating a radom public ip address

weizhouapache commented 5 months ago

this could be implemented via annotation, for example service.beta.kubernetes.io/cloudstack-load-balancer-external-ip