1. 程式人生 > 其它 >Rancher 單節點 Docker 快速部署

Rancher 單節點 Docker 快速部署

版本:v2.5

參考:https://docs.rancher.cn/docs/rancher2.5/quick-start-guide/_index

一、手動快速部署

執行以下命令:

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

結果: Rancher 已經安裝在了 Linux 主機上。

登入 Rancher 介面並配置初始設定:

https://<SERVER_IP>

二、部署工作負載

參考:https://docs.rancher.cn/docs/rancher2.5/quick-start-guide/workload/quickstart-deploy-workload-nodeport/_index

進入Rancher容器並執行一些操作:

root@ubuntu20:~# docker exec -it goofy_banzai /bin/bash
root@9f3273caf126:/var/lib/rancher# apt-get update
root@9f3273caf126:/var/lib/rancher# apt-get install curl wget net-tools
root@9f3273caf126:/var/lib/rancher# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      25/k3s server
tcp        0      0 127.0.0.1:10249         0.0.0.0:*               LISTEN      25/k3s server
tcp        0      0 127.0.0.1:10251         0.0.0.0:*               LISTEN      25/k3s server
tcp        0      0 127.0.0.1:2379          0.0.0.0:*               LISTEN      15/etcd
tcp        0      0 127.0.0.1:10252         0.0.0.0:*               LISTEN      25/k3s server
tcp        0      0 127.0.0.1:6444          0.0.0.0:*               LISTEN      25/k3s server
tcp        0      0 127.0.0.1:2380          0.0.0.0:*               LISTEN      15/etcd
tcp        0      0 127.0.0.1:6060          0.0.0.0:*               LISTEN      8/rancher
tcp        0      0 0.0.0.0:31599           0.0.0.0:*               LISTEN      25/k3s server  暴露的節點埠
tcp        0      0 127.0.0.1:10256         0.0.0.0:*               LISTEN      25/k3s server
tcp        0      0 127.0.0.1:10010         0.0.0.0:*               LISTEN      39/containerd
tcp6       0      0 :::10250                :::*                    LISTEN      25/k3s server
tcp6       0      0 :::6443                 :::*                    LISTEN      25/k3s server
tcp6       0      0 :::80                   :::*                    LISTEN      8/rancher
tcp6       0      0 :::8115                 :::*                    LISTEN      730/channelserver
tcp6       0      0 :::443                  :::*                    LISTEN      8/rancher
tcp6       0      0 :::444                  :::*                    LISTEN      8/rancher
udp        0      0 0.0.0.0:8472            0.0.0.0:*

訪問hello-world服務:

root@9f3273caf126:/var/lib/rancher# curl http://localhost:31599
<html>
  <head>
    <title>Rancher</title>
    <link rel="icon" href="img/favicon.png">
    <style>
      body {
        background-color: white;
        text-align: center;
        padding: 50px;
        font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
      }
      button {
          background-color: #0075a8;
          border: none;
          color: white;
          padding: 15px 32px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 16px;
      }

      #logo {
        margin-bottom: 40px;
      }
    </style>
  </head>
  <body>
    <img id="logo" src="img/rancher-logo.svg" alt="Rancher logo" width=400 />
    <h1>Hello world!</h1>
    <h3>My hostname is hello-world-64cf9cf9f4-zfpqn</h3>
    <div id='Services'>
      <h3>k8s services found 3</h3>

      <b>HELLO_WORLD</b> tcp://10.43.69.230:80<br />

      <b>HELLO_WORLD_NODEPORT</b> tcp://10.43.91.114:80<br />

      <b>KUBERNETES</b> tcp://10.43.0.1:443<br />
...

三、命令列工具

root@ubuntu20:~# apt-get install kubectl=1.19.8-00
root@ubuntu20:~# apt-mark hold kubectl kubelet kubeadm
root@ubuntu20:~# apt-get install bash-completion
root@ubuntu20:~# source <(kubectl completion bash)
root@ubuntu20:~# kubectl completion bash >/etc/bash_completion.d/kubectl
root@ubuntu20:~# mkdir .kube
root@ubuntu20:~# vim .kube/config
apiVersion: v1
kind: Config
clusters:
- name: "local"
  cluster:
    #server: "https://192.168.100.10/k8s/clusters/local"
    server: "https://127.0.0.1/k8s/clusters/local"
    certificate-authority-data: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJoekNDQ\
      VM2Z0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQTdNUnd3R2dZRFZRUUtFeE5rZVc1aGJXbGoKY\
      kdsemRHVnVaWEl0YjNKbk1Sc3dHUVlEVlFRREV4SmtlVzVoYldsamJHbHpkR1Z1WlhJdFkyRXdIa\
      GNOTWpFdwpOekV5TURFek1ERXhXaGNOTXpFd056RXdNREV6TURFeFdqQTdNUnd3R2dZRFZRUUtFe\
      E5rZVc1aGJXbGpiR2x6CmRHVnVaWEl0YjNKbk1Sc3dHUVlEVlFRREV4SmtlVzVoYldsamJHbHpkR\
      1Z1WlhJdFkyRXdXVEFUQmdjcWhrak8KUFFJQkJnZ3Foa2pPUFFNQkJ3TkNBQVNhQ3ZWSlo4UHVId\
      VlCNnBsQ2RVQkUwSVhsUDRYZ2ZsM2x3SW9ySmU0TApJYmlqVlN2ZVJSbFlubWdGMi9xS2VhMjJBb\
      FVZbUFnczhPZEVER0hCYXZ4Um95TXdJVEFPQmdOVkhROEJBZjhFCkJBTUNBcVF3RHdZRFZSMFRBU\
      UgvQkFVd0F3RUIvekFLQmdncWhrak9QUVFEQWdOSEFEQkVBaUFZMDVMYk5RTVYKcXJZTkxibFNaU\
      kRQR1B2bDA0aVpXSmRwUHJjbW51M0E1QUlnTDNxK1VEdGhxWVF3VW5TZ1UvWHRIMnV2Qmp4NApOb\
      mo0Z0dKeXhaVTA3Mkk9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0="

users:
- name: "local"
  user:
    token: "kubeconfig-user-96gnt:ghnk54jqfgmb48759v9qcv2bvfsdmz5678p2m9q9ggpb6frtdh54l6"


contexts:
- name: "local"
  context:
    user: "local"
    cluster: "local"

current-context: "local"

root@ubuntu20:~# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok
controller-manager   Healthy   ok
etcd-0               Healthy   {"health":"true"}
root@ubuntu20:~# kubectl get nodes
NAME         STATUS   ROLES    AGE     VERSION
local-node   Ready    master   4h38m   v1.19.8+k3s1
作者:Varden 出處:http://www.cnblogs.com/varden/ 本文內容如有雷同,請聯絡作者! 本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連線,否則保留追究法律責任的權利。