본문 바로가기

리눅스

쿠버네티스 대시보드를 통해 Nginx를 배포하는 방법

반응형

쿠버네티스 대시보드를 통해 Nginx를 배포하는 방법

쿠버네티스 대시보드 설치

더보기

---

1. 쿠버네티스 대시보드 설치 명령 실행
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
2. 관리자 서비스 계정 및 클러스터 롤 바인딩 생성
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
EOF

cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
EOF
3. 토큰 확인
kubectl create token admin-user -n kubernetes-dashboard

---

쿠버네티스 대시보드를 사용한 Nginx 배포

브라우저에서 대시보드 접속

kubernetes_dashboard

nginx deployment 생성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

터미널에서 Deployment, Pod 정보 확인

Deployment 정보 확인

kubectl describe deployment nginx-deployment
$ kubectl describe deployment nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Sat, 20 Jul 2024 22:25:59 +0900
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.14.2
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-cbdccf466 (2/2 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  13m   deployment-controller  Scaled up replica set nginx-deployment-cbdccf466 to 2

Pods 목록 확인

kubectl get pods -l app=nginx
$ kubectl get pods -l app=nginx
NAME                               READY   STATUS    RESTARTS   AGE
nginx-deployment-cbdccf466-f5cws   1/1     Running   0          13m
nginx-deployment-cbdccf466-xzzcg   1/1     Running   0          13m

Pods에 대한 정보 표시

kubectl describe pod <pod-name>
kubectl describe pod nginx-deployment-cbdccf466-f5cws
$ kubectl describe pod nginx-deployment-cbdccf466-f5cws
Name:             nginx-deployment-cbdccf466-f5cws
Namespace:        default
Priority:         0
Service Account:  default
Node:             worker2/192.168.10.113
Start Time:       Sat, 20 Jul 2024 22:25:59 +0900
Labels:           app=nginx
                  pod-template-hash=cbdccf466
Annotations:      cni.projectcalico.org/containerID: fee374f1abdd8a85b91d7cfe215bbe8cf41b6c48597a4a5db38bf59cca6ecf19
                  cni.projectcalico.org/podIP: 10.244.189.73/32
                  cni.projectcalico.org/podIPs: 10.244.189.73/32
Status:           Running
IP:               10.244.189.73
IPs:
  IP:           10.244.189.73
Controlled By:  ReplicaSet/nginx-deployment-cbdccf466
Containers:
  nginx:
    Container ID:   containerd://aced1b3436ced789ef0a2229a183c0e4e75f374936030fa4bc9d093a3ffa55c0
    Image:          nginx:1.14.2
    Image ID:       docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 20 Jul 2024 22:26:01 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-4425g (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-4425g:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  16m   default-scheduler  Successfully assigned default/nginx-deployment-cbdccf466-f5cws to worker2
  Normal  Pulled     16m   kubelet            Container image "nginx:1.14.2" already present on machine
  Normal  Created    16m   kubelet            Created container nginx
  Normal  Started    16m   kubelet            Started container nginx

 

참고URL

- Kubernetes Documentation : Run a Stateless Application Using a Deployment

 

728x90
반응형