Due to the nested nature of kind I can't figure out what port to use or how to configure it so that I can just type localhost to get to it.
KIND YAML:
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
- role: worker
Also tried:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 8080
hostPort: 80
protocol: TCP
- role: worker
- role: worker
- role: worker
- role: worker
Getting nodes up: kind create cluster --config ~/go/kindconfigs/kind-config.yaml
JOB YAML:
# hello-kubernetes.yaml
apiVersion: v1
kind: Service
metadata:
name: hello-kubernetes
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: hello-kubernetes
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.8
ports:
- containerPort: 8080
running it: kubectl apply -f ~/go/kindconfigs/hello-kubernetes.yaml
Referring from docs you need to use extraPortMappings
to allow the local host to make requests to the hello-kubernetes over port 80
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 8080
hostPort: 80
protocol: TCP
EOF
The deployment needs to be changed as well
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.8
securityContext:
capabilities:
drop:
- ALL
add:
- NET_BIND_SERVICE
ports:
- containerPort: 8080
hostPort: 80
With above configuration you can use localhost:80
to access the hello-kubernetes application.
Note-1: Without above configuration you could access it via NODEIP:NODEPORT
To get NODEIP
kubectl get nodes -o wide
To get NODEPORT
kubectl describe svc hello-kubernetes
Node-2: LoadBalancer
type service only works on supported cloud environments. That's why in a kind cluster running locally on your system you need to use NODEIP
andNODEPORT
to access it.
Note-3: You can try metallb with kind for making LoadBalancer
type service work .This should solve EXTERNAL-IP
pending issue.