【问题标题】:Where does gcloud store its defaults?gcloud 在哪里存储其默认值?
【发布时间】:2018-08-19 02:56:33
【问题描述】:

在this Quickstart之后,我设置了一个这样的默认项目

$ gcloud config set project lfs258
Updated property [core/project].
$ gcloud config get-value project
lfs258

不过,我的 GCP 帐户中不存在 lfs258 项目,所以我很惊讶我可以将其设置为默认值。当我尝试查看 gcloud 存储其默认值的位置时,没有 .gcloud/ 目录。

gcloud 在哪里存储其默认值? kubectl 将它们存储在 .kube/config 中,但我找不到类似的 gcloud 配置文件。

【问题讨论】:

    标签: google-cloud-platform google-compute-engine gcloud


    【解决方案1】:

    更具体地说,gcloud 支持多种配置。运行

    gcloud config configurations list
    

    查看完整列表。

    如果用户没有显式创建配置,他/她将获得名为 default 的配置,结果属性设置通过

    gcloud config set ...
    

    命令将被存储在

    ~/.config/gcloud/configurations/config_default
    

    如果您创建新配置

    gcloud config configurations create my_settings
    

    然后属性将存储在

    ~/.config/gcloud/configurations/config_my_settings
    

    请注意,作为用户,您不应该关心它们的存储位置,如果您需要以编程方式访问它们,更好的选择是运行

    gcloud config list --format=json
    

    您甚至可以通过以下方式访问特定配置(不仅仅是当前选择的)

    gcloud config list --format=json --configuration=my_setting
    

    【讨论】:

      【解决方案2】:

      更通用的是,您始终可以运行gcloud info 打印出一堆诊断信息,以显示所有配置文件和位置以及日志等等。下面是我的环境中的gcloud info 输出,你可以看到配置文件在 用户配置目录:部分。

      $ gcloud info                                                                                                                                                                                                    
      Google Cloud SDK [239.0.0]
      
      Platform: [Mac OS X, x86_64] ('Darwin', 'foorbar.local', '18.2.0', 'Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64', 'x86_64', 'i386')
      Python Version: [2.7.15 (default, Nov 27 2018, 21:40:55)  [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]]
      Python Location: [/usr/local/opt/python@2/bin/python2.7]
      Site Packages: [Enabled]
      
      Installation Root: [/Users/devy/.google-cloud-sdk]
      Installed Components:
        kubectl: [2019.03.17]
        core: [2019.03.17]
        gcloud: []
        docker-credential-gcr: []
        gsutil: [4.37]
        bq: [2.0.42]
        alpha: [2019.02.22]
      System PATH: [REDACTED]
      Python PATH: [REDACTED]
      Cloud SDK on PATH: [True]
      Kubectl on PATH: [/usr/local/bin/kubectl]
      
      Installation Properties: [/Users/devy/.google-cloud-sdk/properties]
      User Config Directory: [/Users/devy/.config/gcloud]
      Active Configuration Name: [default]
      Active Configuration Path: [/Users/devy/.config/gcloud/configurations/config_default]
      
      Account: [devy@foobar.com]
      Project: [foo-bar]
      
      Current Properties:
        [core]
          project: [foo-bar]
          account: [devy@foobar.com]
          disable_usage_reporting: [True]
        [container]
          cluster: [foobar]
        [compute]
          region: [us-central1]
          zone: [us-central1-a]
      
      Logs Directory: [/Users/devy/.config/gcloud/logs]
      Last Log File: [/Users/devy/.config/gcloud/logs/2019.03.19/16.39.09.777341.log]
      
      git: [git version 2.19.1]
      ssh: [OpenSSH_7.9p1, LibreSSL 2.7.3]
      

      在这种特殊情况下,您可以运行gcloud info | grep 'User Config' 来列出配置文件的位置,无论您是否自定义安装。

      【讨论】:

        【解决方案3】:

        存储在~/.config/gcloud/configurations/config_default

        【讨论】:

          猜你喜欢
          • 2017-01-02
          • 2019-07-27
          • 1970-01-01
          • 2015-11-30
          • 1970-01-01
          • 1970-01-01
          • 2019-08-15
          • 1970-01-01
          • 2017-12-02
          相关资源
          最近更新 更多