How to create config map and secrets using golang kubernetes API

huangapple go评论82阅读模式
英文:

How to create config map and secrets using golang kubernetes API

问题

使用Go语言的Kubernetes API如何创建配置映射(ConfigMap)和密钥(Secrets)?

英文:

How to create config map and secrets using Go lang Kubernetes API

答案1

得分: 6

你需要配置你的Kubernetes客户端与你的Kubernetes集群,并创建ConfigMap/Secret结构并调用Kubernetes API。

以下是一个可以使用的代码示例:

cm := corev1.ConfigMap{
  TypeMeta: metav1.TypeMeta{
    Kind:       "ConfigMap",
    APIVersion: "v1",
  },
  ObjectMeta: metav1.ObjectMeta{
    Name:      "my-config-map",
    Namespace: "my-namespace",
  },
  Data: <config-map-data>,
}

clientset.CoreV1().ConfigMaps("my-namespace").Create(&cm)

你可以在以下文档中找到更多信息:

英文:

You need to have your Kubernetes client configured with your Kubernetes cluster and then create ConfigMap/Secret struct and call Kubernetes API.

Here is a code example you can use:

cm := corev1.ConfigMap{
  TypeMeta: metav1.TypeMeta{
    Kind:       &quot;ConfigMap&quot;,
    APIVersion: &quot;v1&quot;,
  },
  ObjectMeta: metav1.ObjectMeta{
    Name:      &quot;my-config-map&quot;,
    Namespace: &quot;my-namespace&quot;,
  },
  Data: &lt;config-map-data&gt;,
}

clientset.CoreV1().ConfigMaps(&quot;my-namespace&quot;).Create(&amp;cm)

Here you can find the doc for:

huangapple
  • 本文由 发表于 2021年12月14日 15:55:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/70345467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定