apiVersion: v1
kind: Pod
metadata:
name: pnlp-pod
spec:
containers:
- name: pnlp-pod
image: pacotheai-docker-public.bintray.io/pnlp:0.1.0
ports:
containerPort: 5050
Kubernetes: Using MetalLB to expose a service
Intro
Once we have our Kubernetes cluster, it’s time to deploy something in it. I’m going to follow a simple deploying a Ratpack application I did sometime ago and that I packed as a docker image at Bintray.
Installing POD
Pod declaration
In the POD declaration I’m defining the Docker image url. And the port where the application is exposed.
How to deploy my POD
kubectl create -f pnlp-pod.yml
How to see deployed POD details
If we want to see things like which private IP is the app exposed, we can use:
kubectl describe pods/pnlp-pod.yml
How to destroy my POD
In case we would like to terminate the POD:
kubectl delete pods pnlp-pod.yml
Installing service
We’re using a Load Balancer
to expose our service to a public IP.
MetalLB configuration
MetalLB is nowadays the only load balancer available for a barebone Kubernetes solution. It will expose our application in the available public IPs. In order to provide MetalLB with a range of available IPs we can deploy a MetalLB configuration to Kubernetes like the following:
I’m using my Vagrant Kubernetes image which already has MetalLB installed and configured. |
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: my-ip-space
protocol: layer2
addresses:
- 192.168.250.112/29
Service definition
Ok so we’ve already deployed our application but it’s not publicly
available, it would be nice to publish it to the outside world. In order
to do that we need to define a service of type LoadBalancer
.
apiVersion: v1
kind: Service
metadata:
name: pnlp-pod
labels:
name: pnlp-pod
spec:
type: LoadBalancer
ports:
- port: 80
selector:
name: pnlp-pod
How to deploy service
kubectl create -f pnlp-service.yml
Check where the service’s been deployed ?
kubectl get services