美文网首页
如何宿主机上操作Rancher2部署的K8S集群

如何宿主机上操作Rancher2部署的K8S集群

作者: Anan9527 | 来源:发表于2018-08-23 20:09 被阅读0次

    在遇到这个问题之后,我曾在微信群里面咨询过,得到了一个大致的方向,但是网上的文章都有些问题,现给出一个可行解决方案
    1.首先安装kubectl,安装kubectl有多种方法,我这里给出一个我认为最简单的方法

    cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    name=Kubernetes
    baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    EOF
    #关闭SeLinux
    setenforce 0
    #yum安装kubuctl
    yum install -y  kubectl
    

    2.创建kube配置目录

    [root@180730-wuguozhu-rancher-1 ~]# mkdir ~/.kube
    [root@180730-wuguozhu-rancher-1 ~]# cd .kube/
    

    3.获取config文件内容


    第一步.png
    第二步.png

    4.在~/.kube下创建config文件

    [root@180730-wuguozhu-rancher-1 ~]# vim .kube/config
    #内容如下:
    apiVersion: v1
    kind: Config
    clusters:
    - name: "k8s1"
      cluster:
        server: "https://192.168.108.45/k8s/clusters/c-crhfd"
        api-version: v1
        certificate-authority-data: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM3akNDQ\
          WRhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFvTVJJd0VBWURWUVFLRXdsMGFHVXQKY\
          21GdVkyZ3hFakFRQmdOVkJBTVRDV05oZEhSc1pTMWpZVEFlRncweE9EQTNNekF3TnpRMk16WmFGd\
          zB5T0RBMwpNamN3TnpRMk16WmFNQ2d4RWpBUUJnTlZCQW9UQ1hSb1pTMXlZVzVqYURFU01CQUdBM\
          VVFQXhNSlkyRjBkR3hsCkxXTmhNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ\
          0tDQVFFQW54NUc4T0M0SDFJR3FVbEYKb1JFODVnM1dVM0JqanNzZHIvamtKaGpSdjFZaTBQcHRsc\
          y9sdWV4Y1BFdWg5bE9qb2N3b0xJaU5rWExRdm5iOQprS01XN1k1THFHZENoNE1qMkdzaSs4a3R6Z\
          2RBL1NKZnhPVlNUeTdGYlUrZkpkeTBYcGlnZG9iS1VMOVRaTVZwCnFSakFNcGVVSytQUUVmb3k1V\
          DN6YkRQMnZaSTBCZlhDbmVGRFBobDhFRkI0eGRiSms5KzFUWTdNUERMZU55YloKNmxvTW9YZFVBe\
          UMzeEozdWs3Tm5PZkY2Y0NvU3RPVGpMNkV0VUpySHFycktYRlZlMWRhWE5YTmlGTlpVZkJoQwprQ\
          2Z2WEYyb2g0bW0ybURVTndGNGViMEV4T0g0OWpsRThvZnFkZ0YxRWNOZVVQQjg5TkQ1b1VmcHdEQ\
          kJKZFJpCng1Y1NZd0lEQVFBQm95TXdJVEFPQmdOVkhROEJBZjhFQkFNQ0FxUXdEd1lEVlIwVEFRS\
          C9CQVV3QXdFQi96QU4KQmdrcWhraUc5dzBCQVFzRkFBT0NBUUVBbWpsbTJMTzVPY0VZSC90Y1Iyb\
          2l3TWIweWt2eTFwRHNzNFJCZHN1eAp1RUFJaGs0c1pPVzUwUHVNQk1QYTBQVDc0L1RmaWlaaUQ1N\
          0pPbVJQSUFLZUVISFRJNmVDNUJLczBiWGRBemFJCnpLRDdKOFJlVnVMUXNzY29TUE9GUDdjeVFBa\
          2VFTVl4b1V4d01qbXBDT08vd1JsdHVVS3lRMDArY0tvYlp0UGYKdGNjRkNHdHlIUFQvOXplUG5TZ\
          3kxMjdPOWp4QkRuT1BHTXdYSE9LazlSQUw0azA0c2xvNDdVUVArdXBlRkhpaAp6OVIzVHBLOHJxW\
          XNHSURJcnJYT1gwcFQvbmNPOFZwbS9hWGduQ3JYYm1VMExhRHczbzNTelhaZGIrMHMxbWdxCjU2d\
          EJGTEFMVUxodkNZREZ3bW1ES2x2b2U1VUltb241djZENk9Dd0t1aVZJWEE9PQotLS0tLUVORCBDR\
          VJUSUZJQ0FURS0tLS0tCg=="
    
    users:
    - name: "user-8lkvq"
      user:
        token: "kubeconfig-user-8lkvq:ssf58twdxblq4j4nqdj7lbj79mzlprpvflptkm56rhc2p7wg2v2jwx"
    
    contexts:
    - name: "k8s1"
      context:
        user: "user-8lkvq"
        cluster: "k8s1"
    
    current-context: "k8s1"
    

    保存退出
    5.验证

    [root@180730-wuguozhu-rancher-1 .kube]# kubectl get pod
    NAME                            READY     STATUS    RESTARTS   AGE
    myapp-66b9c6858-mgb8r           1/1       Running   1          22d
    pg4test-5dc6795d8c-rfnpt        1/1       Running   1          20d
    pgtest-8659cbf97c-wf8rp         1/1       Running   2          20d
    pgtest3-657fc7f7df-q4hgf        1/1       Running   2          20d
    pgtest4-7f9c67df79-w424v        1/1       Running   2          19d
    test-localpv-6b7c544dc7-t4g45   1/1       Running   2          20d
    [root@180730-wuguozhu-rancher-1 .kube]#
    

    完成!
    总结:其他官网和其他博客说的基本都要翻墙,因此我找了个阿里云的镜像,这篇文章的价值在于整理出来一个可行方案,感谢阿里

    相关文章

      网友评论

          本文标题:如何宿主机上操作Rancher2部署的K8S集群

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