CKA (Certified Kubernetes Administrator)/Kode Kloud

07. Networking - Ingress Networking (2)

seulseul 2022. 2. 3. 15:29

 

07. Networking

01. Explore Environment
02. CNI weave
03. Deploy Network Solution
04. Networking Weave
05. Service Networking
06. CoreDNS in Kubernetes
07. CKA – Ingress Networking – 1  Ingress Networking (1)
08. CKA – Ingress Networking – 2 Ingress Networking (2)

 

 

01. We have deployed two applications. Explore the setup.

 

Note: They are in a different namespace.

 

02. Let us now deploy an Ingress Controller. First, create a namespace called ingress-space.

이제 인그레스 컨트롤러를 배포해 보겠습니다. 먼저 ingress-space라는 네임스페이스를 만듭니다.

We will isolate all ingress related objects into its own namespace.

모든 인그레스 관련 개체를 자체 네임스페이스로 격리합니다.

- Name: ingress-space

 

root@controlplane:~# k create namespace ingress-space
namespace/ingress-space created

 

03. The NGINX Ingress Controller requires a ConfigMap object.

NGINX 수신 컨트롤러에는 ConfigMap 개체가 필요합니다.

 

Create a ConfigMap object in the ingress-space.
인그레스 공간에 ConfigMap 객체를 생성합니다.


Use the spec given below. No data needs to be configured in the ConfigMap.

아래 주어진 사양을 사용하십시오. ConfigMap에서 데이터를 구성할 필요가 없습니다.

 
  • Name: nginx-configuration
kubectl create configmap nginx-configuration --namespace ingress-space

 

04. The NGINX Ingress Controller requires a ServiceAccount.

Create a ServiceAccount in the ingress-space namespace.


Use the spec provided below.

 
  • Name: ingress-serviceaccount

k create sa ingress-serviceaccount --namespace ingress-space

root@controlplane:~# k create sa ingress-serviceaccount --namespace ingress-space
serviceaccount/ingress-serviceaccount created

 

05. We have created the Roles and RoleBindings for the ServiceAccount. Check it out!!

 

Ok

 

06. Let us now deploy the Ingress Controller. Create a deployment using the file given.

이제 Ingress Controller를 배포해 보겠습니다. 주어진 파일을 사용하여 배포를 만듭니다.

 

The Deployment configuration is given at /root/ingress-controller.yaml.

배포 구성은 /root/ingress-controller.yaml에서 제공됩니다.

 

There are several issues with it. Try to fix them.

몇 가지 문제가 있습니다. 문제를 해결하십시오.

  • Deployed in the correct namespace.
  • Replicas: 1
  • Use the right image
  • Namespace: ingress-space
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ingress-controller
  namespace: ingress-space
spec:
  replicas: 1
  selector:
    matchLabels:
      name: nginx-ingress
  template:
    metadata:
      labels:
        name: nginx-ingress
    spec:
      serviceAccountName: ingress-serviceaccount
      containers:
        - name: nginx-ingress-controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.21.0
          args:
            - /nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
            - --default-backend-service=app-space/default-http-backend
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - name: http
              containerPort: 80
            - name: https
              containerPort: 443

 

07. Let us now create a service to make Ingress available to external users.


Create a service following the given specs.

 

 
  • Name: ingress
  • Type: NodePort
  • Port: 80
  • TargetPort: 80
  • NodePort: 30080
  • Namespace: ingress-space
  • Use the right selector
Use the command 

kubectl expose deployment ingress-controller --type=NodePort --port=80 \
--name=ingress --dry-run=client -o yaml > ingress.yaml 

and manually add the given node port and namespace.

 

Solution manifest file to create a new ingress service in ingress-space namespace as follows:

---
apiVersion: v1
kind: Service
metadata:
  name: ingress
  namespace: ingress-space
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    nodePort: 30080
    name: http
  - port: 443
    targetPort: 443
    protocol: TCP
    name: https
  selector:
    name: nginx-ingress

 

08. Create the ingress resource to make the applications available at /wear and /watch on the Ingress service.


Create the ingress in the app-space namespace.

 
  • Ingress Created
  • Path: /wear
  • Path: /watch
  • Configure correct backend service for /wear
  • Configure correct backend service for /watch
  • Configure correct backend port for /wear service
  • Configure correct backend port for /watch service
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-wear-watch
  namespace: app-space
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /wear
        pathType: Prefix
        backend:
          service:
           name: wear-service
           port: 
            number: 8080
      - path: /watch
        pathType: Prefix
        backend:
          service:
           name: video-service
           port:
            number: 8080

 

09. Access the application using the Ingress tab on top of your terminal.

Make sure you can access the right applications at /wear and /watch paths.

Ok