client-go 操作k8s常用API
deployment// 列出 deploymentListdeploymentList, err := clientset.AppsV1().Deployments("default").List(metav1.ListOptions{})// 查询 deploymentGetdeploymentGet, err := clientset.AppsV1().Deployme...
·
deployment
// 列出 deploymentList
deploymentList, err := clientset.AppsV1().Deployments("default").List(metav1.ListOptions{})
// 查询 deploymentGet
deploymentGet, err := clientset.AppsV1().Deployments("default").Get("nginx-web-v2", metav1.GetOptions{})
// 创建 deploymentCreate
deploymentCreate, err := clientset.AppsV1().Deployments("default").Create(deploymentName)
// 更新 deploymentUpdate
deploymentUpdate, err := clientset.AppsV1().Deployments("default").Update(deploymentName)
// 删除deployment
err = clientset.AppsV1().Deployments("default").Delete("deploymentName", &metav1.DeleteOptions{})
pod
不写命令空间 即列出所有pod
//列出pod
podList, err := clientset.CoreV1().Pods("default").List(&meta_v1.ListOptions{})
//查询pod
pod, err := clientset.CoreV1().Pods("default").Get(<podName>, meta_v1.GetOptions{})
//创建pod
pod, err := clientset.CoreV1().Pods("default").Create(web)
//更新pod
pod, err := clientset.CoreV1().Pods("default").Update(web)
//删除pod
err := clientset.CoreV1().Pods("default").Delete(<podName>, &meta_v1.DeleteOptions{})
statefulset
// 列出 statefulList
statefulList, err := clientset.AppsV1().StatefulSets("default").List(metav1.ListOptions{})
// 查询 statefulGet
statefulGet, err := clientset.AppsV1().StatefulSets("default").Get("web", metav1.GetOptions{})
// 创建 statefulCreate
statefulCreate, err := clientset.AppsV1().StatefulSets("default").Create(statefulName)
// 更新 statefulUpdate
statefulUpdate, err := clientset.AppsV1().StatefulSets("default").Update(statefulName)
// 删除 stateful
err = clientset.AppsV1().StatefulSets("default").Delete("statefulName", &metav1.DeleteOptions{})
service
// 列出 serviceList
serviceList, err := clientset.CoreV1().Services("default").List(metav1.ListOptions{})
// 查询 serviceGet
serviceGet, err := clientset.CoreV1().Services("default").Get("web", metav1.GetOptions{})
// 创建 serviceCreate
serviceCreate, err := clientset.CoreV1().Services("default").Create(web)
// 更新 serviceUpdate
serviceUpdate, err := clientset.CoreV1().Services("default").Update(web)
// 删除 service
err = clientset.CoreV1().Services.("default").Delete("serviceName", &metav1.DeleteOptions{})
ingress
// 列出 ingressList
ingressList, err := clientset.ExtensionsV1beta1().Ingresses("default").List(metav1.ListOptions{})
// 查询 ingressGet
ingressGet, err := clientset.ExtensionsV1beta1().Ingresses("default").Get("web", metav1.GetOptions{})
// 创建 ingressCreate
ingressCreate, err := clientset.ExtensionsV1beta1().Ingresses("default").Create(web)
// 更新 ingressUpdate
ingressUpdate, err := clientset.ExtensionsV1beta1().Ingresses("default").Update(web)
// 删除 ingress
err = clientset.ExtensionsV1beta1().Ingresses("default").Delete("web", &metav1.DeleteOptions{})
更多推荐
已为社区贡献4条内容
所有评论(0)