美文网首页
rancher 2.6 在Mac 系统安装

rancher 2.6 在Mac 系统安装

作者: 土豆特别想爬山 | 来源:发表于2022-07-06 13:11 被阅读0次

    一、安装 k3d 和 k8s 工具 helm & kubectl

    1.1 安装k3d

    % brew install k3d
    HOMEBREW_CORE_GIT_REMOTE set: using https://mirrors.ustc.edu.cn/homebrew-core.git for Homebrew/core Git remote.
    remote: Enumerating objects: 752, done.
    remote: Counting objects: 100% (752/752), done.
    remote: Total 5347 (delta 752), reused 752 (delta 752), pack-reused 4595
    Receiving objects: 100% (5347/5347), 3.09 MiB | 2.13 MiB/s, done.
    Running `brew update --auto-update`...
    Resolving deltas: 100% (3736/3736), completed with 367 local objects.
    From https://mirrors.ustc.edu.cn/homebrew-core
       8694f05dc6b..4319e7edff7  master     -> origin/master
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> New Formulae
    adamstark-audiofile       dumpling                  gold                      kt-connect                lexicon                   llvm@13                   podman-compose            trzsz-go
    aztfy                     evernote-backup           hwatch                    leapp-cli                 libpython-tabulate        nb                        qbe                       tuc
    czg                       fastnetmon                jaq                       levant                    livekit                   poac                      req                       vectorscan
    
    You have 35 outdated formulae installed.
    You can upgrade them with brew upgrade
    or list them with brew outdated.
    
    ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/k3d-5.4.3.monterey.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring k3d-5.4.3.monterey.bottle.tar.gz
    ==> Caveats
    zsh completions have been installed to:
      /usr/local/share/zsh/site-functions
    ==> Summary
    🍺  /usr/local/Cellar/k3d/5.4.3: 9 files, 18.2MB
    ==> Running `brew cleanup k3d`...
    Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    

    1.2 安装kubectl

    % brew install kubectl
    kubernetes-cli 1.24.1 is already installed but outdated (so it will be upgraded).
    ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/kubernetes-cli-1.24.2.monterey.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Upgrading kubectl
      1.24.1 -> 1.24.2 
    
    ==> Pouring kubernetes-cli-1.24.2.monterey.bottle.tar.gz
    ==> Caveats
    zsh completions have been installed to:
      /usr/local/share/zsh/site-functions
    ==> Summary
    🍺  /usr/local/Cellar/kubernetes-cli/1.24.2: 228 files, 56.4MB
    ==> Running `brew cleanup kubernetes-cli`...
    Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    Removing: /usr/local/Cellar/kubernetes-cli/1.24.1... (228 files, 56.3MB)
    Removing: /Users/yqg/Library/Caches/Homebrew/kubernetes-cli--1.24.1.monterey.bottle.tar.gz... (15.9MB)
    ==> Upgrading 1 dependent of upgraded formula:
    Disable this behaviour by setting HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    minikube 1.25.2 -> 1.26.0
    ==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/minikube-1.26.0.monterey.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Upgrading minikube
      1.25.2 -> 1.26.0 
    
    ==> Pouring minikube-1.26.0.monterey.bottle.tar.gz
    ==> Caveats
    zsh completions have been installed to:
      /usr/local/share/zsh/site-functions
    ==> Summary
    🍺  /usr/local/Cellar/minikube/1.26.0: 9 files, 72.4MB
    ==> Running `brew cleanup minikube`...
    Removing: /usr/local/Cellar/minikube/1.25.2... (9 files, 72.3MB)
    Removing: /Users/yqg/Library/Caches/Homebrew/minikube--1.25.2.monterey.bottle.tar.gz... (30.2MB)
    ==> Checking for dependents of upgraded formulae...
    ==> No broken dependents found!
    ==> Caveats
    ==> kubernetes-cli
    zsh completions have been installed to:
      /usr/local/share/zsh/site-functions
    ==> minikube
    zsh completions have been installed to:
      /usr/local/share/zsh/site-functions
    

    1.3 安装helm,如已安装可以跳过

    % brew install helm
    Warning: helm 3.9.0 already installed
    

    二、创建 k8s 集群,增加Rancher管理

    2.1 创建k3d-rancher集群负载均衡,端口是443

    % k3d cluster create k3d-rancher --api-port 6550 --servers 1 --agents 3 --port 443:443@loadbalancer --wait
    
    INFO[0000] portmapping '443:443' targets the loadbalancer: defaulting to [servers:*:proxy agents:*:proxy] 
    INFO[0000] Prep: Network                                
    INFO[0000] Created network 'k3d-k3d-rancher'            
    INFO[0000] Created image volume k3d-k3d-rancher-images  
    INFO[0000] Starting new tools node...                   
    INFO[0001] Creating node 'k3d-k3d-rancher-server-0'     
    INFO[0007] Pulling image 'docker.io/rancher/k3s:v1.23.6-k3s1' 
    INFO[0013] Pulling image 'ghcr.io/k3d-io/k3d-tools:5.4.3' 
    INFO[0492] Starting Node 'k3d-k3d-rancher-tools'        
    INFO[0629] Creating node 'k3d-k3d-rancher-agent-0'      
    INFO[0629] Creating node 'k3d-k3d-rancher-agent-1'      
    INFO[0629] Creating node 'k3d-k3d-rancher-agent-2'      
    INFO[0629] Creating LoadBalancer 'k3d-k3d-rancher-serverlb' 
    INFO[0634] Pulling image 'ghcr.io/k3d-io/k3d-proxy:5.4.3' 
    INFO[1085] Using the k3d-tools node to gather environment information 
    INFO[1085] Starting new tools node...                   
    INFO[1085] Starting Node 'k3d-k3d-rancher-tools'        
    INFO[1086] Starting cluster 'k3d-rancher'               
    INFO[1086] Starting servers...                          
    INFO[1087] Starting Node 'k3d-k3d-rancher-server-0'     
    INFO[1091] Starting agents...                           
    INFO[1092] Starting Node 'k3d-k3d-rancher-agent-0'      
    INFO[1092] Starting Node 'k3d-k3d-rancher-agent-2'      
    INFO[1092] Starting Node 'k3d-k3d-rancher-agent-1'      
    INFO[1103] Starting helpers...                          
    INFO[1103] Starting Node 'k3d-k3d-rancher-serverlb'     
    INFO[1110] Injecting records for hostAliases (incl. host.k3d.internal) and for 6 network members into CoreDNS configmap... 
    INFO[1112] Cluster 'k3d-rancher' created successfully!  
    INFO[1113] You can now use it like this:                
    kubectl cluster-info
    % kubectl cluster-info
    I0628 17:49:41.274978   30932 versioner.go:84] Right kubectl missing, downloading version 1.23.6+k3s1
    Downloading https://storage.googleapis.com/kubernetes-release/release/v1.23.6/bin/darwin/amd64/kubectl
    kubectl1.23.6+k3s1 100% |████████████████████████████████████████| (53/53 MB, 65.427 kB/s) [13m12s:0s] done.
    Kubernetes control plane is running at https://0.0.0.0:6550
    CoreDNS is running at https://0.0.0.0:6550/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    Metrics-server is running at https://0.0.0.0:6550/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy
    
    To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
    
    

    2.2 查看k3d集群

    % k3d cluster list
    NAME          SERVERS   AGENTS   LOADBALANCER
    k3d-rancher   1/1       3/3      true
    

    2.3 新建kubeconfig ,这样就可以用kubectl命令了

    % KUBECONFIG_FILE=~/.kube/k3d-rancher
    % k3d kubeconfig get k3d-rancher > $KUBECONFIG_FILE
    % export KUBECONFIG=$KUBECONFIG_FILE
    % kubectl get nodes
    NAME                       STATUS   ROLES                  AGE    VERSION
    k3d-k3d-rancher-agent-0    Ready    <none>                 100m   v1.23.6+k3s1
    k3d-k3d-rancher-agent-2    Ready    <none>                 100m   v1.23.6+k3s1
    k3d-k3d-rancher-server-0   Ready    control-plane,master   100m   v1.23.6+k3s1
    k3d-k3d-rancher-agent-1    Ready    <none>                 100m   v1.23.6+k3s1
    

    2.4 安装Rancher

    添加helm 仓库

    % helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
    % helm repo add jetstack https://charts.jetstack.io
    % helm repo list
    NAME            URL                                                                   
    rancher-latest  https://releases.rancher.com/server-charts/latest
    jetstack        https://charts.jetstack.io  
    % helm repo update
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "rancher-latest" chart repository
    ...Successfully got an update from the "jetstack" chart repository
    Update Complete. ⎈Happy Helming!⎈
    

    安装证书

    % kubectl apply --validate=false -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.2/cert-manager.crds.yaml
    customresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io created
    customresourcedefinition.apiextensions.k8s.io/certificates.cert-manager.io created
    customresourcedefinition.apiextensions.k8s.io/challenges.acme.cert-manager.io created
    customresourcedefinition.apiextensions.k8s.io/clusterissuers.cert-manager.io created
    customresourcedefinition.apiextensions.k8s.io/issuers.cert-manager.io created
    customresourcedefinition.apiextensions.k8s.io/orders.acme.cert-manager.io created
    % kubectl create namespace cert-manager
    namespace/cert-manager created
    % helm install \
      cert-manager jetstack/cert-manager \
      --namespace cert-manager \
      --version v1.8.2 --wait
    Error: INSTALLATION FAILED: timed out waiting for the condition
    % kubectl get pod -n cert-manager                                
    NAME                                       READY   STATUS    RESTARTS   AGE
    cert-manager-cainjector-58c8955c5d-69ln8   1/1     Running   0          3h17m
    cert-manager-67599dcc49-zvzdn              1/1     Running   0          3h17m
    cert-manager-webhook-d698b4885-fsvrx       1/1     Running   0          3h17m
    

    安装rancher

    % kubectl create namespace cattle-system
    namespace/cattle-system created
    % helm install rancher rancher-latest/rancher \
      --namespace cattle-system \
      --set hostname=rancher.k3d.localhost --wait
    
    Error: INSTALLATION FAILED: timed out waiting for the condition
    % kubectl -n cattle-system rollout status deploy/rancher
    
    deployment "rancher" successfully rolled out
    % kubectl get pods -n cattle-system
    NAME                               READY   STATUS      RESTARTS      AGE
    rancher-post-delete-qp7ws          0/1     Completed   0             23h
    rancher-webhook-5b65595df9-ss5sw   1/1     Running     0             14h
    rancher-7bd5d865df-n7hdq           1/1     Running     6 (61m ago)   23h
    rancher-7bd5d865df-5vcjf           1/1     Running     4 (61m ago)   23h
    rancher-7bd5d865df-q5c6l           1/1     Running     8 (57m ago)   23h
    

    三、使用rancher

    3.1 打开https://rancher.k3d.localhost

    如果用谷歌浏览器,会提示页面不是私密的,直接用键盘敲:thisisunsafe,即可进入页面;
    如果用其他浏览器,编辑/etc/hosts,增加一行:
    127.0.0.1 rancher.k3d.localhost
    打开页面如图:

    rancher

    3.2 设置rancher

    helm查看密码:

    % kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{"\n"}}'
    8s6rjwnmzc26899pbxqg45fl4zvtlq7hzn684m5lskwsbqphhn9v58
    

    输入密码后,进入:


    重置密码

    设置密码后,continue,进入:


    欢迎页
    查看集群:
    image.png

    参考资料:https://itnext.io/rancher-2-4-kubernetes-on-your-macos-laptop-with-docker-k3d-b578b1c7568b

    相关文章

      网友评论

          本文标题:rancher 2.6 在Mac 系统安装

          本文链接:https://www.haomeiwen.com/subject/nkqzvrtx.html