IaaS/퍼블릭클라우드

(AWS) EKS를 사용할때 Dashboard를 외부에서 접속하게 하기 (feat. ingress)

armyost 2021. 8. 19. 17:33
728x90

Dashboard 설치 및 배포

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.5/aio/deploy/recommended.yaml
$ kubectl get deploy -n kubernetes-dashboard

 


eks-admin 서비스 계정 및 클러스터 역할 바인딩 만들기

$ cat > eks-admin-service-account.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: eks-admin
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: eks-admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: eks-admin
namespace: kube-system
EOF

 

$ kubectl apply -f eks-admin-service-account.yaml




Nginx 수신 컨트롤러(NLB) 생성

$ wget -O aws_nlb_nginx_ingress_controller.yaml https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/deploy.yaml
$ kubectl apply -f aws_nlb_nginx_ingress_controller.yaml
$ kubectl get svc -n ingress-nginx

 

 

위 작업을 하시면 AWS의 EC2 콘솔의 로드벨런서에서 아래와 같은 로드벨런서가 추가됩니다. 




Nginx 수신 컨트롤러(NLB)에 대한 룰셋(Ingress) 생성

 

$ cat > ingress-dashboard.yaml << EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dashboard
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^(/dashboard)$ $1/ redirect;
  namespace: kubernetes-dashboard
spec:
  rules:
  - http:
      paths:
      - path: /dashboard(/|$)(.*)
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 443
EOF

 

$ kubectl apply -f ingress-dashboard.yaml
$ kubectl get ingress -n kubernetes-dashboard




토큰 값 확인 및 대시보드 접속

$kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep eks-admin | awk '{print $1}')

 

$ kubectl get svc -n ingress-nginx



명령어로 주소 확인 후 https://주소값/dashboard/를 주소에 접속하여 확인한 토큰 값을 통해 로그인. 끝.