• Configure Access to Multiple Clusters


    Configure Access to Multiple Clusters

    Install and Set Up kubectl

    curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
    
    chmod +x ./kubectl
    
    sudo mv ./kubectl /usr/local/bin/kubectl
    
    

    Configure Access to Multiple Clusters

    Create a directory named config-exercise. In your config-exercise directory, create a file named config-demo with this content:

    apiVersion: v1
    kind: Config
    preferences: {}
    
    clusters:
    - cluster:
      name: development
    - cluster:
      name: scratch
    
    users:
    - name: developer
    - name: experimenter
    
    contexts:
    - context:
      name: dev-frontend
    - context:
      name: dev-storage
    - context:
      name: exp-scratch
    

    Go to your config-exercise directory. Enter these commands to add cluster details to your configuration file:

    kubectl config --kubeconfig=config-demo set-cluster development --server=https://1.2.3.4 --certificate-authority=fake-ca-file
    kubectl config --kubeconfig=config-demo set-cluster scratch --server=https://5.6.7.8 --insecure-skip-tls-verify
    
    

    Add user details to your configuration file:

    kubectl config --kubeconfig=config-demo set-credentials developer --client-certificate=fake-cert-file --client-key=fake-key-seefile
    kubectl config --kubeconfig=config-demo set-credentials experimenter --username=exp --password=some-password
    

    Add context details to your configuration file:

    
    kubectl config --kubeconfig=config-demo set-context dev-frontend --cluster=development --namespace=frontend --user=developer
    kubectl config --kubeconfig=config-demo set-context dev-storage --cluster=development --namespace=storage --user=developer
    kubectl config --kubeconfig=config-demo set-context exp-scratch --cluster=scratch --namespace=default --user=experimenter
    

    Open your config-demo file to see the added details. As an alternative to opening the config-demo file, you can use the config view command.

    kubectl config --kubeconfig=config-demo view
    

    The output shows the two clusters, two users, and three contexts:

    apiVersion: v1
    clusters:
    - cluster:
        certificate-authority: fake-ca-file
        server: https://1.2.3.4
      name: development
    - cluster:
        insecure-skip-tls-verify: true
        server: https://5.6.7.8
      name: scratch
    contexts:
    - context:
        cluster: development
        namespace: frontend
        user: developer
      name: dev-frontend
    - context:
        cluster: development
        namespace: storage
        user: developer
      name: dev-storage
    - context:
        cluster: scratch
        namespace: default
        user: experimenter
      name: exp-scratch
    current-context: ""
    kind: Config
    preferences: {}
    users:
    - name: developer
      user:
        client-certificate: fake-cert-file
        client-key: fake-key-seefile
    - name: experimenter
      user:
        password: some-password
        username: exp
    
    

    Set the current context:

    kubectl config --kubeconfig=config-demo use-context dev-frontend
    
    

    To see only the configuration information associated with the current context, use the --minify flag.

    kubectl config --kubeconfig=config-demo view --minify
    
    

    The output shows configuration information associated with the dev-frontend context:

    apiVersion: v1
    clusters:
    - cluster:
        certificate-authority: fake-ca-file
        server: https://1.2.3.4
      name: development
    contexts:
    - context:
        cluster: development
        namespace: frontend
        user: developer
      name: dev-frontend
    current-context: dev-frontend
    kind: Config
    preferences: {}
    users:
    - name: developer
      user:
        client-certificate: fake-cert-file
        client-key: fake-key-seefile
    
    

    Change the current context to exp-scratch:

    kubectl config --kubeconfig=config-demo use-context exp-scratch
    

    View configuration associated with the new current context, exp-scratch.

    kubectl config --kubeconfig=config-demo view --minify
    

    Finally, suppose you want to work for a while in the storage namespace of the development cluster.
    Change the current context to dev-storage:

    kubectl config --kubeconfig=config-demo use-context dev-storage
    

    View configuration associated with the new current context, `dev-storage.

    kubectl config --kubeconfig=config-demo view --minify
    
  • 相关阅读:
    datatable一些用法续
    验证视图状态MAC失败
    datatable应用select方法后变成行数组的问题的解决
    [jQuery] html中两个select之间option元素的add与remove,多值上传
    [VBS] 使用vbs文件保证程序运行,并模拟键盘回车键
    [jQuery] 为table各行添加不同颜色的class
    [转]谈谈个人网站建设和经营
    [jQuery] jquery如何reset表单(form)
    兼容Firefox IE Chrome的onkeydown事件处理方法
    [bat] 使用bat文件保证指定程序运行
  • 原文地址:https://www.cnblogs.com/Ethan2lee/p/7546065.html
Copyright © 2020-2023  润新知