본문 바로가기
IT 기술/k8s

[cka] Ingress Networking - 2

by Geunny 2024. 8. 13.
반응형

1. We have deployed two applications. Explore the setup. Note: They are in a different namespace.

 

controlplane ~ ➜  k get all -A
NAMESPACE      NAME                                       READY   STATUS    RESTARTS   AGE
app-space      pod/default-backend-78f6fb8b4-sxpj7        1/1     Running   0          54s
app-space      pod/webapp-video-74bdc86cb8-xms4v          1/1     Running   0          54s
app-space      pod/webapp-wear-6f8947f6cc-kvrwb           1/1     Running   0          54s
kube-flannel   pod/kube-flannel-ds-xjmls                  1/1     Running   0          3m8s
kube-system    pod/coredns-768b85b76f-k9zmh               1/1     Running   0          3m7s
kube-system    pod/coredns-768b85b76f-zzmd5               1/1     Running   0          3m7s
kube-system    pod/etcd-controlplane                      1/1     Running   0          3m20s
kube-system    pod/kube-apiserver-controlplane            1/1     Running   0          3m20s
kube-system    pod/kube-controller-manager-controlplane   1/1     Running   0          3m20s
kube-system    pod/kube-proxy-spgkg                       1/1     Running   0          3m8s
kube-system    pod/kube-scheduler-controlplane            1/1     Running   0          3m20s

NAMESPACE     NAME                           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
app-space     service/default-http-backend   ClusterIP   10.110.214.107   <none>        80/TCP                   54s
app-space     service/video-service          ClusterIP   10.99.199.79     <none>        8080/TCP                 54s
app-space     service/wear-service           ClusterIP   10.103.159.187   <none>        8080/TCP                 54s
default       service/kubernetes             ClusterIP   10.96.0.1        <none>        443/TCP                  3m22s
kube-system   service/kube-dns               ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   3m19s

NAMESPACE      NAME                             DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-flannel   daemonset.apps/kube-flannel-ds   1         1         1       1            1           <none>                   3m20s
kube-system    daemonset.apps/kube-proxy        1         1         1       1            1           kubernetes.io/os=linux   3m21s

NAMESPACE     NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
app-space     deployment.apps/default-backend   1/1     1            1           54s
app-space     deployment.apps/webapp-video      1/1     1            1           54s
app-space     deployment.apps/webapp-wear       1/1     1            1           54s
kube-system   deployment.apps/coredns           2/2     2            2           3m19s

NAMESPACE     NAME                                        DESIRED   CURRENT   READY   AGE
app-space     replicaset.apps/default-backend-78f6fb8b4   1         1         1       54s
app-space     replicaset.apps/webapp-video-74bdc86cb8     1         1         1       54s
app-space     replicaset.apps/webapp-wear-6f8947f6cc      1         1         1       54s
kube-system   replicaset.apps/coredns-768b85b76f          2         2         2       3m8s

 

 

2. Let us now deploy an Ingress Controller. First, create a namespace called ingress-nginx. We will isolate all ingress related objects into its own namespace.

 

controlplane ~ ➜  k create namespace ingress-nginx
namespace/ingress-nginx created

 

 

3. The NGINX Ingress Controller requires a ConfigMap object. Create a ConfigMap object with name ingress-nginx-controller in the ingress-nginx namespace. No data needs to be configured in the ConfigMap.

controlplane ~ ➜  k create configmap ingress-nginx-controller -n ingress-nginx
configmap/ingress-nginx-controller created

 

4. The NGINX Ingress Controller requires two ServiceAccounts. Create both ServiceAccount with name ingress-nginx and ingress-nginx-admission in the ingress-nginx namespace. Use the spec provided below.

 

controlplane ~ ➜   kubectl create serviceaccount ingress-nginx --namespace ingress-nginx
serviceaccount/ingress-nginx created

controlplane ~ ✖ kubectl create serviceaccount ingress-nginx-admission --namespace ingress-nginx
serviceaccount/ingress-nginx-admission created

 

5. We have created the Roles, RoleBindings, ClusterRoles, and ClusterRoleBindings for the ServiceAccount. Check it out!!

 

6. Let us now deploy the Ingress Controller. Create the Kubernetes objects using the given file. The Deployment and it's service configuration is given at /root/ingress-controller.yaml. 

There are several issues with it. Try to fix them. Note: Do not edit the default image provided in the given file. The image validation check passes when other issues are resolved.

 

 

/root/ingress-controller.yam 파일을 열어 오타들 수정.

 

7. Create the ingress resource to make the applications available at /wear and /watch on the Ingress service. Also, make use of rewrite-target annotation field: - 

 

nginx.ingress.kubernetes.io/rewrite-

 

target: / Ingress resource comes under the namespace scoped, so don't forget to create the ingress in the app-space namespace.

 

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

'IT 기술 > k8s' 카테고리의 다른 글

[cka] TroubleShooting - Application Failure  (0) 2024.08.25
[cka] Cluster Installation using Kubeadm  (0) 2024.08.25
[cka] Ingress Networking - 1  (0) 2024.08.13
[cka] CoreDNS in Kubernetes  (0) 2024.08.10
[cka] Service Networking  (0) 2024.08.09

댓글