'Kubernetes - How to access deployments in minikube?
I have used the following configurations to deploy an app on minikube.
Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: angular-app
spec:
replicas: 2
selector:
matchLabels:
run: angular-app
template:
metadata:
labels:
run: angular-app
spec:
containers:
- name: angular-app
image: nheidloff/angular-app
ports:
- containerPort: 80
- containerPort: 443
Service:
apiVersion: v1
kind: Service
metadata:
name: angular-app
labels:
run: angular-app
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
Service description:
Name: angular-app
Namespace: default
Labels: run=angular-app
Annotations: <none>
Selector: <none>
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.174.98
IPs: 10.102.174.98
Port: http 80/TCP
TargetPort: 80/TCP
NodePort: http 31503/TCP
Endpoints: 172.17.0.3:80,172.17.0.4:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
When i try to access the endpoints, the links are not responding. However after using minikube service angular-app. Following showed up:
|-----------|-------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------|-------------|---------------------------|
| default | angular-app | http/80 | http://192.168.49.2:31503 |
|-----------|-------------|-------------|---------------------------|
🏃 Starting tunnel for service angular-app.
|-----------|-------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------|-------------|------------------------|
| default | angular-app | | http://127.0.0.1:60611 |
|-----------|-------------|-------------|------------------------|
With this ip http://127.0.0.1:60611 im able to access the app. What is the use of the endpoints given in the service description? How to access each replica? Say if i have 4 replicas, how do i access each one of them?
Solution 1:[1]
The answer from ~al-waleed-shihadeh is correct, but I want to give some additional info.
You should be able to access the service via the NodePort, too, without needing the
minikube servicecommand: http://192.168.49.2:31503 . The port is assigned at random, but you can choose a fixed one in the range 30000-32767spec: type: NodePort ports: - port: 80 targetPort: 80 protocol: TCP name: http nodePort: 30080If you want a 'normal' URL to access the service, you must add an Ingress that allow access to the service via a reverse proxy. It will route to one of your services' pods using load-balancing.
If you want fixed URL's to each of your pods separately, you could use a StatefulSet instead of a Deployment, and create 4 different services with selectors for angular-app-0 to angular-app-3, and then have 4 different ingresses as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GeertPt |
