Все упомянутые файлы включены ниже. Я пытаюсь создать прокси NGINX, чтобы обслуживать мой сервер и интерфейс с одним и тем же доменом.
Nginx работает успешно, я могу сказать, потому что я получаю ошибку 404 от nginx, когда я нажимаю root url, заданный kubectl get ingress
.
Когда я нажимаю url/hello
конечная точка, однако я получаю 503 Service Temporarily Unavailable
ошибку от Nginx.
Кто-нибудь сталкивался с этой ошибкой?
Вот файл yaml для моей команды kubectl create -f
:
kind: Service
apiVersion: v1
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
annotations:
# by default the type is elb (classic load balancer).
service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
# this setting is to make sure the source IP address is preserved.
externalTrafficPolicy: Local
type: LoadBalancer
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
ports:
- name: http
port: 80
targetPort: http
# - name: https
# port: 443
# targetPort: https
---
kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /hello
backend:
serviceName: go-hello
servicePort: 8080
---
kind: Pod
apiVersion: v1
metadata:
name: go-hello
labels:
app: go-hello
spec:
containers:
- name: go-hello
image: docker.io/chsclarke11/test-go
---
kind: Service
apiVersion: v1
metadata:
name: go-hello-service
spec:
selector:
app: go-hello
ports:
- port: 8080 # Default port for image
вот файл Docker для приложения go-hello:
FROM golang:1.12-alpine
RUN apk add --no-cache git
# Set the Current Working Directory inside the container
WORKDIR /app
RUN go mod download
COPY . .
# Build the Go app
RUN go build -o main
# This container exposes port 8080 to the outside world
EXPOSE 8080
# Run the binary program produced by `go install`
CMD ["./main"]
Вот приложение go -hello mock:
package main
import (
"fmt"
"net/http"
)
func main() {
fmt.Printf("starting server at http://localhost:8080")
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}