Hi I’m learning Helm and Kubernetes. I’m stuck, I can’t access my app from outside the cluster.
I’m using minikube v1.32.0 wit docker’s drivers.
I tried to use LoadBalancers, NodePorts, Tunnels, Services. Every time i get 404 or connection time out.
This is my app’s chart:
# Source: app-chart/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: release-name-app-chart
labels:
helm.sh/chart: app-chart-0.1.0
app.kubernetes.io/name: app-chart
app.kubernetes.io/instance: release-name
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
automountServiceAccountToken: true
---
# Source: app-chart/templates/service.yaml
kind: Service
apiVersion: v1
metadata:
name: app-service
spec:
allocateLoadBalancerNodePorts: false
selector:
app: helmapp
ports:
- protocol: "TCP"
# Port accessible inside cluster
port: 8080
# Port to forward to inside the pod
targetPort: 8080
type: LoadBalancer
My deployment:
# Source: app-chart/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: release-name-app-chart
labels:
helm.sh/chart: app-chart-0.1.0
app.kubernetes.io/name: app-chart
app.kubernetes.io/instance: release-name
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: app-chart
app.kubernetes.io/instance: release-name
app: helmapp
template:
metadata:
labels:
helm.sh/chart: app-chart-0.1.0
app.kubernetes.io/name: app-chart
app.kubernetes.io/instance: release-name
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
app: helmapp
spec:
serviceAccountName: release-name-app-chart
securityContext:
{}
containers:
- image: "myrepo/helm-app:latest"
name: app-chart
ports:
- containerPort: 8080
protocol: TCP
resources:
{}
My ingress:
# Source: app-chart/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: release-name-app-chart
labels:
helm.sh/chart: app-chart-0.1.0
app.kubernetes.io/name: app-chart
app.kubernetes.io/instance: release-name
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: spring
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-service
port:
number: 8080
My app It’s a simple SpringBoot project with an endpoint that returns code 200.
@GetMapping("/health")
public ResponseEntity<String> healthCheck() {
return ResponseEntity.ok("OK");
}
2
Answers
Thanks to everyone, i solved my problem. The error was about my image. It was pulling an old version of my image so building and pushing a new one solved my problem. The tunnel started changing docker password. ( https://github.com/kubernetes/minikube/issues/11580#issuecomment-1337288420 )
Minikube requires the use of
minikube tunnel
to issue an IP that allows you to access the service from outside the cluster.Once you have that running in a separate terminal window, you should find an IP assigned to your service, and when that happens you can use
localhost:{port}/{path}
to access your serviceI took your yaml and created this in order to test if the setup was correct (I swapped out your image for the basic
tomcat
to check if its your image or config. Tomcat still runs on 8080)This gives me a pod like this:
And also a service:
The "EXTERNAL-IP" field value of 127.0.0.1 for app-service will only appear if
minikube tunnel
successfully started upIf we
kubectl log
the new pod we can see some details:Now, if we (from the host machine) try to curl localhost on port 8080, that should go through the tunnel and access the service if everything is setup right
Okay, so we get a 404, but look at the last bit:
<h3>Apache Tomcat/10.1.19</h3>
And compare that with the log message:
08-Mar-2024 18:00:29.866 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.1.19]
This confirms your config is right and you’ve mapped everything correctly.
The 404 you’re getting would imply your server is not handling the requests right.
Finally,
This is not an ingress. What you have inside this file is a Helm test hook (https://helm.sh/docs/helm/helm_test/)
An ingress is something completely different and you can read about that here: https://kubernetes.io/docs/concepts/services-networking/ingress/