In a kind/minikube/etc. cluster, start a deployment (a workload resource that manages a pod replicaset)
kubectl create deployment home --image=b4bz/homer
expose the deployment, i.e. make it receive comms from other containers or the outside.
kubectl expose deploy/home --port 8080
-> make sure the port exposed is actually the one the container exposes, e.g. for postgres this would 5432, for b4bz/homer it is 8080. There is no default here.
The command above creates a service of the type ClusterIP, which makes it accessible to other services only within cluster.
To make it accessible outside the cluster, the service has to be of type NodePort
, like so
kubectl expose deploy/home --type=NodePort --port 8080
Now, how to you open it in a browser using kind, k8s? Well, you can port-forward from the localhost to the container port using kubectl port-forward
- checking out kubectl port-forward --help
clarifies a lot.
kubectl port-forward services/home :8080
# assigns a random localhost port to the port 8080 of the container
Top comments (0)