Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduced LoadBalancer for service #27

Merged
merged 1 commit into from
Aug 24, 2023
Merged

feat: introduced LoadBalancer for service #27

merged 1 commit into from
Aug 24, 2023

Conversation

stevensbkang
Copy link
Member

@stevensbkang stevensbkang commented Aug 24, 2023

This PR is to introduce the LoadBalancer service type to close #15.

Implementation

For the deployment, if the service type is detected as the LoadBalancer, it follows the same process as NodePort, where it loops through the list of ports defined in the .spec.ports, but the difference is the hostBinding.HostPort becomes the service port, so the low-end port is published at the host level.

Example YAML
apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 80
    targetport: 80
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

For the GET part, it sets the external-ip to match the server IP address where k2d runs. An example run below:

Example Run
(⎈|k2d:N/A)➜  k2d-lb (feat/lb) k get svc                                                                                                                                                                        [1:47:00]  ✭
NAME           TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)    AGE
my-nginx-svc   LoadBalancer   192.168.148.2   192.168.68.250   8080/TCP   75s
(⎈|k2d:N/A)➜  k2d-lb (feat/lb) curl 192.168.68.250:8080                                                                                                                                                         [1:48:18]  ✭
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>

Also, as part of this PR, I have added an exclusion of the ExternalName service type we do not support yet.

@stevensbkang stevensbkang added this to the 1.0.0-beta milestone Aug 24, 2023
@stevensbkang stevensbkang self-assigned this Aug 24, 2023
@deviantony deviantony removed this from the 1.0.0-beta milestone Aug 24, 2023
Copy link
Member

@deviantony deviantony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@deviantony deviantony merged commit 548d9f6 into develop Aug 24, 2023
1 check passed
@deviantony deviantony deleted the feat/lb branch August 24, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "Load Balancer" service types.
2 participants