본문 바로가기
시스템/쿠버네티스

쿠버네티스 대시보드 설치

by cbwstar 2024. 1. 8.
728x90
반응형

1.  공식 k8s dashboard yaml 다운받아 설치

wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
vi recommended.yaml

 kind: Service
 33 apiVersion: v1
 34 metadata:
 35   labels:
 36     k8s-app: kubernetes-dashboard
 37   name: kubernetes-dashboard
 38   namespace: kubernetes-dashboard
 39 spec:
 40   ports:
 41     - port: 443
 42       nodePort: 31055
 43       targetPort: 8443
 44   selector:
 45     k8s-app: kubernetes-dashboard
 46   type: NodePort

42라인 nodePort 추가
46라인 type: NodePort 추가

kubectl apply -f recommended.yaml

 

2. dashboard service 확인

 - namespace는 kubernetes-dashboard 

root@master:~/dashboard# kubectl get svc -n kubernetes-dashboard
NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
dashboard-metrics-scraper   ClusterIP   10.107.64.31    <none>        8000/TCP        39m
kubernetes-dashboard        NodePort    10.107.41.120   <none>        443:31055/TCP   39m

 

3. 외부 접속을 위해 NodePort 설정

기본은 Type이 ClusterIp로 되어 있음 Type를 NodePort로 변경해 줘야 외부에서 접속이 된다.

apiVersion: v1
  6 kind: Service
  7 metadata:
  8   annotations:
  9     kubectl.kubernetes.io/last-applied-configuration: |
 10       {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kubernetes-dashboard"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"},"type":"NodePort"}}
 11   creationTimestamp: "2024-01-08T08:06:30Z"
 12   labels:
 13     k8s-app: kubernetes-dashboard
 14   name: kubernetes-dashboard
 15   namespace: kubernetes-dashboard
 16   resourceVersion: "105594"
 17   uid: fac08362-93c7-4197-8736-1e7104371ef5
 18 spec:
 19   clusterIP: 10.107.41.120
 20   clusterIPs:
 21   - 10.107.41.120
 22   externalTrafficPolicy: Cluster
 23   internalTrafficPolicy: Cluster
 24   ipFamilies:
 25   - IPv4
 26   ipFamilyPolicy: SingleStack
 27   ports:
 28   - nodePort: 31055
 29     port: 443
 30     protocol: TCP
 31     targetPort: 8443
 32   selector:
 33     k8s-app: kubernetes-dashboard
 34   sessionAffinity: None
 35   type: NodePort
 36 status:
 37   loadBalancer: {}

/* 28 라인 nodePort 추가 */
/* 35 라인type : NodePort로 변경 없으면 추가 */

 

4. 브라우저에서 접속 확인(마스터 아이피 또는 노드 아이피로 접속)

http가 아닌 https로 접속해야 함

토큰이 있어야 로그인이 된다.

 

5. 토큰 생성

   vi dashboard-admin.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

 

kubectl create -f dashboard-admin.yaml

 

5. 토큰제한 시간 변경

  - 디폴트 토큰은 만료기간이 짧다. 지속시간을 무제한으로 변경

kubectl edit -n kubernetes-dashboard deployments.apps kubernetes-dashboard

spec:
 38       containers:
 39       - args:
 40         - --auto-generate-certificates
 41         - --namespace=kubernetes-dashboard
 42         - --token-ttl=0
 43         image: kubernetesui/dashboard:v2.7.0
 44         imagePullPolicy: Always
 45         livenessProbe:
 46           failureThreshold: 3
 47           httpGet:
 48             path: /
 49             port: 8443
 50             scheme: HTTPS
 51           initialDelaySeconds: 30
 52           periodSeconds: 10
 53           successThreshold: 1
 54           timeoutSeconds: 30
 55         name: kubernetes-dashboard


/* 41 라인 밑에 token-ttl=0 추가 0값이면 무제한 */

 

6. 토큰 발행

kubectl -n kubernetes-dashboard create token admin-user

root@master:~/dashboard# kubectl -n kubernetes-dashboard create token admin-user
eyJhbGciOiJSUzI1NiIsImtpZCI6IjNRUDd5MzljTEVtTEhudGFvLS1hRmxROFRCQ2tBc250VUpNOUYtWmtHbGcifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzA0NzA3OTkxLCJpYXQiOjE3MDQ3MDQzOTEsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiYTEzZTUwOGItNDAwMy00NzFmLWE3YWItYTc5OTI2ZjU0YTM2In19LCJuYmYiOjE3MDQ3MDQzOTEsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbi11c2VyIn0.PR7U-mvaT-8QDoARqpAzhbmAajYvtDTfNuBtBZnf52QREU0E-hqbzQ8jh7pUPAHrzWy7kq6FPfG9RYUvNt4Rr82jzx12WFGvjybQyd3LlaJkrWn-u8_Pp5_t2q_de4Wd1CYOwr0AGExr0ICORwdAYyeTjq1yo-tBUvcWoF7cBCE8sFljfgugW8x-KgMVg6qPbdcn6VLZhExVScQ6u-DZGIhcPeaREENXfZcT25VaQTdi0V5QBZzKc3Ze2ky-noEbxr0OWemfdD2CuKqe6mfjYVkBpjPHa0KKqZ4pmToE8Z7huZDJ-ubGPB3IzDXzN3RjCmG2dXuADT9vq2mp-FUPYw
root@master:~/dashboard#

발행된 토큰을 복사해서 로그인한다.

아래는 로그인 화면이다.

 

7. k8s dashboard 제거

root@master:~/dashboard# kubectl delete --all deploy -n kubernetes-dashboard 
deployment.apps "dashboard-metrics-scraper" deleted
deployment.apps "kubernetes-dashboard" deleted
root@master:~/dashboard# kubectl delete --all service -n kubernetes-dashboard 
service "dashboard-metrics-scraper" deleted
service "kubernetes-dashboard" deleted
root@master:~/dashboard#
728x90
반응형

댓글



"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."

loading