如何为我的kubernetes部署和服务创建ingress nginx



我可以使用LoadBalancer服务类型访问我的django应用程序部署,但我试图切换到ClusterIP服务类型和ingress nginx,但当我试图通过主机url访问网站时,我得到了503服务暂时不可用。对入口的描述还示出了CCD_ 1和CCD_。我做错了什么?

这是我的服务和入口yaml:

---
apiVersion: v1
kind: Service
metadata:
name: django-service
spec:
type: ClusterIP
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: django-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/force-ssl-redirect: 'true'
nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
tls:
- hosts:
- django.example.com
rules:
- host: django.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: django-service
port:
number: 80
ingressClassName: nginx

kubectl获取所有

$ kubectl get all
NAME                                        READY   STATUS    RESTARTS   AGE
pod/django-app-5bdd8ffff9-79xzj             1/1     Running   0          7m44s
pod/postgres-58fffbb5cc-247x9               1/1     Running   0          7m44s
NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/django-service   ClusterIP   10.233.29.58    <none>        80/TCP     7m44s
service/pg-service       ClusterIP   10.233.14.137   <none>        5432/TCP   7m44s
NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/django-app             1/1     1            1           7m44s
deployment.apps/postgres               1/1     1            1           7m44s
NAME                                              DESIRED   CURRENT   READY   AGE
replicaset.apps/django-app-5bdd8ffff9             1         1         1       7m44s
replicaset.apps/postgres-58fffbb5cc               1         1         1       7m44s

描述入口

$ kubectl describe ing django-ingress
Name:             django-ingress
Labels:           <none>
Namespace:        django
Address:          10.10.30.50
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
SNI routes django.example.com
Rules:
Host                      Path  Backends
----                      ----  --------
django.example.com
/   django-service:80 (<error: endpoints "django-service" not found>)
Annotations:                nginx.ingress.kubernetes.io/force-ssl-redirect: true
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: true
Events:
Type    Reason  Age                   From                      Message
----    ------  ----                  ----                      -------
Normal  Sync    5m28s (x2 over 6m5s)  nginx-ingress-controller  Scheduled for sync
Normal  Sync    5m28s (x2 over 6m5s)  nginx-ingress-controller  Scheduled for sync

我想您忘记了在服务中建立与部署的链接。

apiVersion: v1
kind: Service
metadata:
name: django-service
spec:
type: ClusterIP
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8000
selector:
app: your-deployment-name

您的标签也必须在部署中设置:

spec:
selector:
matchLabels:
app: your-deployment-name
template:
metadata:
labels:
app: your-deployment-name

相关内容

  • 没有找到相关文章

最新更新