Reputation: 281
I am trying to create Deployment from client-go
but it is not creating and throwing an error as
the server could not find the requested resource
My client-go
version: 4.0.0
My Kubernetes version is:
Client Version:
version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.0", GitCommit:"fff5156092b56e6bd60fff75aad4dc9de6b6ef37", GitTreeState:"clean", BuildDate:"2017-03-28T16:36:33Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version:
version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.3", GitCommit:"029c3a408176b55c30846f0faedf56aae5992e9b", GitTreeState:"clean", BuildDate:"2017-02-15T06:34:56Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
My sample code is
package main
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
intstr "k8s.io/apimachinery/pkg/util/intstr"
kube "k8s.io/client-go/kubernetes"
v1 "k8s.io/client-go/pkg/api/v1"
appsv1beta1 "k8s.io/client-go/pkg/apis/apps/v1beta1"
rest "k8s.io/client-go/rest"
"net"
)
var (
KubeMasterIP = "x.x.x.x"
Port = "xxxx"
UserName = "xxxxx"
Password = "xxxxxxxxxx"
TLSValue = true
Protocol = "https"
NameSpaceName = "test-namespace"
)
func main() {
fmt.Println("***************************")
buildAndDeployApp()
fmt.Println("***************************")
}
func buildAndDeployApp() {
tlsClientConfig := rest.TLSClientConfig{}
tlsClientConfig.Insecure = TLSValue
fmt.Println("HostPath: ", net.JoinHostPort(KubeMasterIP, Port))
restConfig := &rest.Config{
Host: net.JoinHostPort(KubeMasterIP, Port),
Username: UserName,
Password: Password,
TLSClientConfig: tlsClientConfig,
}
cSet, err := kube.NewForConfig(restConfig)
if err != nil {
fmt.Println("Error in Kube clientSet : ", err.Error())
}
deploy, err := cSet.AppsV1beta1().Deployments(NameSpaceName).Create(BuildDeployment())
fmt.Println("Deploy Output: ", deploy)
fmt.Println("Error: ", err)
}
func int32Ptr(i int32) *int32 { return &i }
func BuildDeployment() *appsv1beta1.Deployment {
return &appsv1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-deploy",
},
Spec: appsv1beta1.DeploymentSpec{
Replicas: int32Ptr(1),
Strategy: appsv1beta1.DeploymentStrategy{
Type: "RollingUpdate",
RollingUpdate: &appsv1beta1.RollingUpdateDeployment{
MaxSurge: &intstr.IntOrString{
IntVal: 1,
},
MaxUnavailable: &intstr.IntOrString{
IntVal: 1,
},
},
},
MinReadySeconds: int32(5),
RevisionHistoryLimit: int32Ptr(5),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "demo",
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "web",
Image: "nginx:1.13",
Ports: []v1.ContainerPort{
{
Name: "http",
Protocol: v1.ProtocolTCP,
ContainerPort: 80,
},
},
ImagePullPolicy: "Always",
},
},
RestartPolicy: "Always",
},
},
},
}
}
Upvotes: 3
Views: 111
Reputation: 281
apps/v1beta1 will not work in 1.5, its supported from 1.6. I used extensions/v1beta1 to access deployments in 1.5.
Upvotes: 1