Skip to content

Services

Course: Kubernetes Part 2 - chapter 5

Services let you actually expose your app over the internet.

  • Create a Nodeport service (service.yml)
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30007 # This port can be any valid port within the NodePort range
type: NodePort
  • Apply it
kubectl apply -f service.yml
  • Visit any of the nodes on 30007
http://localhost:30007/

💡 This will only work if you’ve started your kind cluster with the config from slide 2 On vultr, it will just work

LoadBalancer (will only work on a cloud provider)

Section titled “LoadBalancer (will only work on a cloud provider)”

The LoadBalancer service type is designed to work with cloud providers to create an external load balancer that routes traffic to the service.

  • Replace the type to be LoadBalancer
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
  • Re-apply the config
kubectl apply -f service.yml
  • See the loadbalancer created on the dashboard

  • Visit the balancer to see the website