관리 메뉴

피터의 개발이야기

[Rancher] Rancher를 Docker로 설치, minikube 연동 본문

DevOps/Rancher

[Rancher] Rancher를 Docker로 설치, minikube 연동

기록하는 백앤드개발자 2024. 4. 22. 10:05
반응형

ㅁ 들어가며

[Rancher] Rancher란 무엇인가? 에서 Rancher에 대해 알아보았다.

ㅇ 이번 글에서는 Rancher 사용법을 알아보기 위하여 로컬환경에 Docker로 설치를 해보았다. 

ㅇ 설치 후 Minikube로 설치된 클러스터를 연동하였다.

 

ㅁ Docker run

docker run -d --restart=unless-stopped \
  -p 8080:80 -p 8443:443 \
  --name rancher \
  --privileged \
  rancher/rancher:latest

 

ㅁRancher 접속 및 초기 세팅

ㅇ localhost:8080로 접속하였다.

ㅇ 처음 실행하면 Rancher의 bootstrap Password를 설정해야 한다.

ㅇ 위의 password를 화면에 입력하고 log in 하였다.

ㅇ 비밀번호 설정 후 Log in with Local User 계속 버튼을 누른다.

 

 ㅇ admin 비밀번호를 설정하고 약관동의를 체크한다.

ㅇ localhost로 설정하면 다른 클러스터에서 접속이 불가하다.

ㅇ 내부 네트워크의 IP 주소를 세팅하였다.

ㅇ Continue 버튼을 클릭한다.

 

ㅁ Minikube 추가하기

ㅇ Rancher의 홈화면이다.

ㅇ import Existing 버튼을 클릭

 

ㅇ Generic을 선택한다.

ㅇ Cluster Name을 minikube로 입력하고 Create 버튼 클릭

ㅇ Cluster가 생성되었지만, 현재 Pending 상태이다.

 

ㅇ role 설정 및 Agent 설치

# minikube 연결
$ curl --insecure -sfL https://192.168.33.74:8443/v3/import/frslf498dtcbjs4xt7tlxc65hvczdw5z88v7c96ncw7mlpzff7fwqw_c-m-zkl4vf4x.yaml | kubectl apply -f -

ㅇ 권한 설정 yaml를 남겨놓는다.

더보기
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: proxy-clusterrole-kubeapiserver
rules:
- apiGroups: [""]
  resources:
  - nodes/metrics
  - nodes/proxy
  - nodes/stats
  - nodes/log
  - nodes/spec
  verbs: ["get", "list", "watch", "create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: proxy-role-binding-kubernetes-master
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: proxy-clusterrole-kubeapiserver
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: kube-apiserver
---
apiVersion: v1
kind: Namespace
metadata:
  name: cattle-system

---

apiVersion: v1
kind: ServiceAccount
metadata:
  name: cattle
  namespace: cattle-system

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cattle-admin-binding
  namespace: cattle-system
  labels:
    cattle.io/creator: "norman"
subjects:
- kind: ServiceAccount
  name: cattle
  namespace: cattle-system
roleRef:
  kind: ClusterRole
  name: cattle-admin
  apiGroup: rbac.authorization.k8s.io

---

apiVersion: v1
kind: Secret
metadata:
  name: cattle-credentials-8956ae0
  namespace: cattle-system
type: Opaque
data:
  url: "aHR0cHM6Ly8xOTIuMTY4LjMzLjc0Ojg0NDM="
  token: "ZnJzbGY0OThkdGNianM0eHQ3dGx4YzY1aHZjemR3NXo4OHY3Yzk2bmN3N21scHpmZjdmd3F3"
  namespace: ""

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cattle-admin
  labels:
    cattle.io/creator: "norman"
rules:
- apiGroups:
  - '*'
  resources:
  - '*'
  verbs:
  - '*'
- nonResourceURLs:
  - '*'
  verbs:
  - '*'

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cattle-cluster-agent
  namespace: cattle-system
  annotations:
    management.cattle.io/scale-available: "2"
spec:
  selector:
    matchLabels:
      app: cattle-cluster-agent
  template:
    metadata:
      labels:
        app: cattle-cluster-agent
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - preference:
              matchExpressions:
              - key: node-role.kubernetes.io/controlplane
                operator: In
                values:
                - "true"
            weight: 100
          - preference:
              matchExpressions:
              - key: node-role.kubernetes.io/control-plane
                operator: In
                values:
                - "true"
            weight: 100
          - preference:
              matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: In
                values:
                - "true"
            weight: 100
          - preference:
              matchExpressions:
              - key: cattle.io/cluster-agent
                operator: In
                values:
                - "true"
            weight: 1
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: beta.kubernetes.io/os
                operator: NotIn
                values:
                - windows
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - cattle-cluster-agent
              topologyKey: kubernetes.io/hostname
            weight: 100
      serviceAccountName: cattle
      tolerations:
      # No taints or no controlplane nodes found, added defaults
      - effect: NoSchedule
        key: node-role.kubernetes.io/controlplane
        value: "true"
      - effect: NoSchedule
        key: "node-role.kubernetes.io/control-plane"
        operator: "Exists"
      - effect: NoSchedule
        key: "node-role.kubernetes.io/master"
        operator: "Exists"
      containers:
        - name: cluster-register
          imagePullPolicy: IfNotPresent
          env:
          - name: CATTLE_IS_RKE
            value: "false"
          - name: CATTLE_SERVER
            value: "https://192.168.33.74:8443"
          - name: CATTLE_CA_CHECKSUM
            value: "0b19439e46d1076c0e3fff29c19f79f1d96ef68b3b19398d3f604c640624cd73"
          - name: CATTLE_CLUSTER
            value: "true"
          - name: CATTLE_K8S_MANAGED
            value: "true"
          - name: CATTLE_CLUSTER_REGISTRY
            value: ""
          - name: CATTLE_SERVER_VERSION
            value: v2.8.2
          - name: CATTLE_INSTALL_UUID
            value: 941da75d-e36e-4ae3-8efb-0d38330cc272
          - name: CATTLE_INGRESS_IP_DOMAIN
            value: sslip.io
          image: rancher/rancher-agent:v2.8.2
          volumeMounts:
          - name: cattle-credentials
            mountPath: /cattle-credentials
            readOnly: true
      volumes:
      - name: cattle-credentials
        secret:
          secretName: cattle-credentials-8956ae0
          defaultMode: 320
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1

---
apiVersion: v1
kind: Service
metadata:
  name: cattle-cluster-agent
  namespace: cattle-system
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
  - port: 443
    targetPort: 444
    protocol: TCP
    name: https-internal
  selector:
    app: cattle-cluster-agent

 

ㅇ  minikube가 추가된 모습이다.

 

ㅁ Minikube 삭제방법

ㅇ 왼쪽의 Cluster Management를 클릭한다.

ㅇ Minikube를 선택하고 Delete를 클릭한다.

ㅇ Delete를 클릭하면 Cluster가 삭제 된다.

 

 

ㅁ 함께 보면 좋은 사이트

 Rancher Doc

 

반응형

'DevOps > Rancher' 카테고리의 다른 글

[Rancher] Rancher 웹 사용법  (0) 2024.04.21
[Rancher] Rancher란 무엇인가?  (0) 2024.04.21
Comments