亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

谷歌容器集群作為配置

谷歌容器集群作為配置

Go
弒天下 2023-04-04 14:23:49
我正在嘗試將kubernetes go-client與 cloud.google.com/go/container 一起使用。我使用 google cloud go 容器包創建集群,然后我想使用 go-client 在該集群上部署。go-client 給出的集群外示例使用kube 配置文件獲取集群的憑據。但是因為我剛剛在我的應用程序中創建了這個集群,所以我沒有那個配置文件。如何使用“google.golang.org/genproto/googleapis/container/v1”集群設置“k8s.io/client-go/rest”配置?必填字段是什么?下面的代碼是我目前擁有的(沒有顯示實際的 CA 證書)。func getConfig(cluster *containerproto.Cluster) *rest.Config {    return &rest.Config{        Host:     "https://" + cluster.GetEndpoint(),        TLSClientConfig: rest.TLSClientConfig{            Insecure: false,            CAData: []byte(`-----BEGIN CERTIFICATE-----                ...                -----END CERTIFICATE-----`),        },    }它導致此錯誤:x509:由未知授權機構簽名的證書。因此,顯然缺少一些東西。任何其他方法都非常受歡迎!提前致謝
查看完整描述

2 回答

?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

ClientCertificate、ClientKey 和 ClusterCaCertificate 需要按照此處所述進行解碼

func CreateK8sClientFromCluster(cluster *gkev1.Cluster) {

? ? decodedClientCertificate, err := base64.StdEncoding.DecodeString(cluster.MasterAuth.ClientCertificate)

? ? if err != nil {

? ? ? ? fmt.Println("decode client certificate error:", err)

? ? ? ? return

? ? }

? ? decodedClientKey, err := base64.StdEncoding.DecodeString(cluster.MasterAuth.ClientKey)

? ? if err != nil {

? ? ? ? fmt.Println("decode client key error:", err)

? ? ? ? return

? ? }

? ? decodedClusterCaCertificate, err := base64.StdEncoding.DecodeString(cluster.MasterAuth.ClusterCaCertificate)

? ? if err != nil {

? ? ? ? fmt.Println("decode cluster CA certificate error:", err)

? ? ? ? return

? ? }


? ? config := &rest.Config{

? ? ? ? Username: cluster.MasterAuth.Username,

? ? ? ? Password: cluster.MasterAuth.Password,

? ? ? ? Host:? ? ?"https://" + cluster.Endpoint,

? ? ? ? TLSClientConfig: rest.TLSClientConfig{

? ? ? ? ? ? Insecure: false,

? ? ? ? ? ? CertData: decodedClientCertificate,

? ? ? ? ? ? KeyData:? decodedClientKey,

? ? ? ? ? ? CAData:? ?decodedClusterCaCertificate,

? ? ? ? },

? ? }


? ? clientset, err := kubernetes.NewForConfig(config)

? ? if err != nil {

? ? ? ? fmt.Printf("failed to get k8s client set from config: %s\n", err)

? ? ? ? return

? ? }

}


查看完整回答
反對 回復 2023-04-04
?
白板的微信

TA貢獻1883條經驗 獲得超3個贊

基本上,簡而言之,推薦的方法是:

  1. 創建 Google Cloud IAM 服務帳戶 + 下載其 json 密鑰

  2. GOOGLE_APPLICATION_CREDENTIALSenv var 設置為那個 key.json

  3. 從中查找集群的 IP 地址和 CA 證書gcloud container clusters describe(或者只是.kube/config從中獲取文件gcloud get-credentials

  4. 將這些值傳遞給 client-go 并使用環境變量運行您的程序。


查看完整回答
反對 回復 2023-04-04
  • 2 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號