How to create config map and secrets using golang kubernetes API

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

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。

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

  1. cm := corev1.ConfigMap{
  2. TypeMeta: metav1.TypeMeta{
  3. Kind: "ConfigMap",
  4. APIVersion: "v1",
  5. },
  6. ObjectMeta: metav1.ObjectMeta{
  7. Name: "my-config-map",
  8. Namespace: "my-namespace",
  9. },
  10. Data: <config-map-data>,
  11. }
  12. 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:

  1. cm := corev1.ConfigMap{
  2. TypeMeta: metav1.TypeMeta{
  3. Kind: &quot;ConfigMap&quot;,
  4. APIVersion: &quot;v1&quot;,
  5. },
  6. ObjectMeta: metav1.ObjectMeta{
  7. Name: &quot;my-config-map&quot;,
  8. Namespace: &quot;my-namespace&quot;,
  9. },
  10. Data: &lt;config-map-data&gt;,
  11. }
  12. 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:

确定