By default, kubernetes does not come with a loadbalancer which would not restrict you to using only ports 30000-32767 to expose services. The easiest way go being able deploy services on port 80 or 443 without going through a reverse proxy is a project called metallb.
The installation is fairly simple. First, apply the two provided manifests. I'm going to use version 0.12.1
[archy@kube01 ~]$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml
[archy@kube01 ~]$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
Metallb requires a configmap to work. I'm going to use layer2 and give the controller a complete subnet:
[archy@kube01 ~]$ vim /var/tmp/metallb-config.yml
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 172.31.19.0/24
The full example config with comments is available here. Now apply the configmap and your loadbalancer should be ready.
[archy@kube01 ~]$ kubectl apply -f /var/tmp/metallb-config.yml
Here's an example snippet for a service of type 'LoadBalancer':
---
apiVersion: v1
kind: Service
metadata:
name: my-webapp
spec:
type: LoadBalancer
loadBalancerIP: 172.31.11.9
ports:
- name: my-webapp
protocol: TCP
port: 443
targetPort: 443
selector:
app: my-webapp
Feel free to comment and / or suggest a topic.
Comments
Post a Comment