24 Mayıs 2023 Çarşamba

Kubernetes kind: Ingress - Path Based Routing

Giriş
Mantıksal olarak tek bir "host:..." vardır. Bu host için paths altında her path teker teker belirtilir. Şeklen şöyle



Örnek
Şeklen şöyle
Şöyle yaparız
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: simple-fanout-example
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        pathType: Prefix
        backend:
          service:
            name: service1
            port:
              number: 4200
      - path: /bar
        pathType: Prefix
        backend:
          service:
            name: service2
            port:
              number: 8080
Örnek
Burada "host:..." yok. Uygulamaya "localhost:/" şeklinde erişiriz
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: springboot-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: springboot
            port:
              number: 8080
Örnek
Şöyle yaparız. "localhost/user" ve "localhost/order" şeklinde erişiriz
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-path-based
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
   - host: localtest.me
     http:
       paths:
         - path: /order
           pathType: Prefix
           backend:
             service:
               name: order-service
               port:
                 number: 8080
         - path: /user
           pathType: Prefix
           backend:
             service:
               name: user-service
               port:
                 number: 8080
Örnek
Şöyle yaparız. Tek path var.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sample-api-ing
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1 
spec:
  rules:
    - host: sample-api.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: sample-api-svc
                port:
                  number: 8080
Service şöyledir. Bu service Ingress tarafından kullanıldığı için type ClusterIP
apiVersion: v1
kind: Service
metadata:
  name: sample-api-svc
  namespace: default
  labels:
    app: sample-api
spec:
  type: ClusterIP         <----
  selector:
    app: sample-api
  ports:
  - port: 8080
    name: "http"
    protocol: TCP

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...