Last active
May 11, 2020 02:23
-
-
Save junnplus/49dec126a14ae9381690428340e4666a to your computer and use it in GitHub Desktop.
a sample of apiserver https://github.com/kubernetes/apiserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"k8s.io/apimachinery/pkg/runtime" | |
"k8s.io/apimachinery/pkg/runtime/serializer" | |
genericserver "k8s.io/apiserver/pkg/server" | |
genericoptions "k8s.io/apiserver/pkg/server/options" | |
) | |
func NewSecureServingOptions() *genericoptions.SecureServingOptions { | |
o := genericoptions.SecureServingOptions{ | |
BindAddress: net.ParseIP("0.0.0.0"), | |
BindPort: 6443, | |
Required: true, | |
ServerCert: genericoptions.GeneratableKeyCert{ | |
PairName: "apiserver", | |
CertDirectory: "/var/run/apiserver", | |
}, | |
} | |
if err := o.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil { | |
fmt.Println(err) | |
} | |
return &o | |
} | |
var ( | |
// Scheme defines methods for serializing and deserializing API objects. | |
Scheme = runtime.NewScheme() | |
// Codecs provides methods for retrieving codecs and serializers for specific | |
// versions and content types. | |
Codecs = serializer.NewCodecFactory(Scheme) | |
) | |
func main() { | |
genericConfig := genericserver.NewConfig(Codecs) | |
secureServingOption := NewSecureServingOptions() | |
if err := secureServingOption.WithLoopback().ApplyTo( | |
&genericConfig.SecureServing, &genericConfig.LoopbackClientConfig); err != nil { | |
fmt.Println(err) | |
return | |
} | |
completedConfig := genericConfig.Complete(nil) | |
apiserver, err := completedConfig.New("apiserver", genericserver.NewEmptyDelegate()) | |
if err != nil { | |
fmt.Println(err) | |
return | |
} | |
stopCh := genericserver.SetupSignalHandler() | |
fmt.Println("serving...") | |
apiserver.SecureServingInfo.Serve(apiserver.Handler, apiserver.ShutdownTimeout, stopCh) | |
<-stopCh | |
// apiserver.PrepareRun().Run(stopCh) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment