Merge pull request #1149 from aaron-prindle/api-name-configurable
Added API Name as configuration optionpull/1196/head
commit
56d4824456
|
@ -40,6 +40,7 @@ func NewLocalkubeServer() *localkube.LocalkubeServer {
|
|||
APIServerPort: constants.APIServerPort,
|
||||
APIServerInsecureAddress: net.ParseIP("127.0.0.1"),
|
||||
APIServerInsecurePort: 8080,
|
||||
APIServerName: constants.APIServerName,
|
||||
ShouldGenerateCerts: true,
|
||||
ShowVersion: false,
|
||||
RuntimeConfig: map[string]string{"api/all": "true"},
|
||||
|
@ -59,6 +60,8 @@ func AddFlags(s *localkube.LocalkubeServer) {
|
|||
flag.IntVar(&s.APIServerPort, "apiserver-port", s.APIServerPort, "The port the apiserver will listen securely on")
|
||||
flag.IPVar(&s.APIServerInsecureAddress, "apiserver-insecure-address", s.APIServerInsecureAddress, "The address the apiserver will listen insecurely on")
|
||||
flag.IntVar(&s.APIServerInsecurePort, "apiserver-insecure-port", s.APIServerInsecurePort, "The port the apiserver will listen insecurely on")
|
||||
flag.StringVar(&s.APIServerName, "apiserver-name", s.APIServerName, "The apiserver name which is used in the generated certificate for localkube/kubernetes. This can be used if you want to make the API server available from outside the machine")
|
||||
|
||||
flag.BoolVar(&s.ShouldGenerateCerts, "generate-certs", s.ShouldGenerateCerts, "If localkube should generate it's own certificates")
|
||||
flag.BoolVar(&s.ShowVersion, "version", s.ShowVersion, "If localkube should just print the version and exit.")
|
||||
flag.BoolVar(&s.ShowHostIP, "host-ip", s.ShowHostIP, "If localkube should just print the host IP and exit.")
|
||||
|
|
|
@ -53,6 +53,7 @@ const (
|
|||
kvmNetwork = "kvm-network"
|
||||
keepContext = "keep-context"
|
||||
featureGates = "feature-gates"
|
||||
apiServerName = "apiserver-name"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -127,6 +128,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
kubernetesConfig := cluster.KubernetesConfig{
|
||||
KubernetesVersion: viper.GetString(kubernetesVersion),
|
||||
NodeIP: ip,
|
||||
APIServerName: viper.GetString(apiServerName),
|
||||
FeatureGates: viper.GetString(featureGates),
|
||||
ContainerRuntime: viper.GetString(containerRuntime),
|
||||
NetworkPlugin: viper.GetString(networkPlugin),
|
||||
|
@ -140,7 +142,7 @@ func runStart(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
fmt.Println("Setting up certs...")
|
||||
if err := cluster.SetupCerts(host.Driver); err != nil {
|
||||
if err := cluster.SetupCerts(host.Driver, kubernetesConfig.APIServerName); err != nil {
|
||||
glog.Errorln("Error configuring authentication: ", err)
|
||||
cmdUtil.MaybeReportErrorAndExit(err)
|
||||
}
|
||||
|
@ -211,6 +213,7 @@ func init() {
|
|||
startCmd.Flags().String(hypervVirtualSwitch, "", "The hyperv virtual switch name. Defaults to first found. (only supported with HyperV driver)")
|
||||
startCmd.Flags().String(kvmNetwork, "default", "The KVM network name. (only supported with KVM driver)")
|
||||
startCmd.Flags().StringArrayVar(&dockerEnv, "docker-env", nil, "Environment variables to pass to the Docker daemon. (format: key=value)")
|
||||
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for localkube/kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||
startCmd.Flags().StringSliceVar(&insecureRegistry, "insecure-registry", nil, "Insecure Docker registries to pass to the Docker daemon")
|
||||
startCmd.Flags().StringSliceVar(®istryMirror, "registry-mirror", nil, "Registry mirrors to pass to the Docker daemon")
|
||||
startCmd.Flags().String(kubernetesVersion, constants.DefaultKubernetesVersion, "The kubernetes version that the minikube VM will use (ex: v1.2.3) \n OR a URI which contains a localkube binary (ex: https://storage.googleapis.com/minikube/k8sReleases/v1.3.0/localkube-linux-amd64)")
|
||||
|
|
|
@ -854,6 +854,8 @@ _minikube_start()
|
|||
flags_with_completion=()
|
||||
flags_completion=()
|
||||
|
||||
flags+=("--apiserver-name=")
|
||||
local_nonpersistent_flags+=("--apiserver-name=")
|
||||
flags+=("--container-runtime=")
|
||||
local_nonpersistent_flags+=("--container-runtime=")
|
||||
flags+=("--cpus=")
|
||||
|
|
|
@ -15,6 +15,7 @@ minikube start
|
|||
### Options
|
||||
|
||||
```
|
||||
--apiserver-name string The apiserver name which is used in the generated certificate for localkube/kubernetes. This can be used if you want to make the apiserver available from outside the machine (default "minikubeCA")
|
||||
--container-runtime string The container runtime to be used
|
||||
--cpus int Number of CPUs allocated to the minikube VM (default 2)
|
||||
--disk-size string Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g) (default "20g")
|
||||
|
|
|
@ -50,6 +50,7 @@ type LocalkubeServer struct {
|
|||
APIServerPort int
|
||||
APIServerInsecureAddress net.IP
|
||||
APIServerInsecurePort int
|
||||
APIServerName string
|
||||
ShouldGenerateCerts bool
|
||||
ShowVersion bool
|
||||
ShowHostIP bool
|
||||
|
@ -200,7 +201,7 @@ func (lk LocalkubeServer) GenerateCerts() error {
|
|||
fmt.Println("Using these existing CA certs: ", lk.GetCAPublicKeyCertPath(), lk.GetCAPrivateKeyCertPath())
|
||||
} else {
|
||||
fmt.Println("Creating CA cert")
|
||||
if err := util.GenerateCACert(lk.GetCAPublicKeyCertPath(), lk.GetCAPrivateKeyCertPath()); err != nil {
|
||||
if err := util.GenerateCACert(lk.GetCAPublicKeyCertPath(), lk.GetCAPrivateKeyCertPath(), lk.APIServerName); err != nil {
|
||||
fmt.Println("Failed to create CA certs: ", err)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ func localkubeURIWasSpecified(config KubernetesConfig) bool {
|
|||
}
|
||||
|
||||
// SetupCerts gets the generated credentials required to talk to the APIServer.
|
||||
func SetupCerts(d drivers.Driver) error {
|
||||
func SetupCerts(d drivers.Driver, apiServerName string) error {
|
||||
localPath := constants.GetMinipath()
|
||||
ipStr, err := d.GetIP()
|
||||
if err != nil {
|
||||
|
@ -245,7 +245,7 @@ func SetupCerts(d drivers.Driver) error {
|
|||
caKey := filepath.Join(localPath, "ca.key")
|
||||
publicPath := filepath.Join(localPath, "apiserver.crt")
|
||||
privatePath := filepath.Join(localPath, "apiserver.key")
|
||||
if err := GenerateCerts(caCert, caKey, publicPath, privatePath, ip); err != nil {
|
||||
if err := GenerateCerts(caCert, caKey, publicPath, privatePath, ip, apiServerName); err != nil {
|
||||
return errors.Wrap(err, "Error generating certs")
|
||||
}
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ func TestSetupCerts(t *testing.T) {
|
|||
tempDir := tests.MakeTempDir()
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
if err := SetupCerts(d); err != nil {
|
||||
if err := SetupCerts(d, constants.APIServerName); err != nil {
|
||||
t.Fatalf("Error starting cluster: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
|
||||
// Kill any running instances.
|
||||
|
||||
var localkubeStartCmdTemplate = "/usr/local/bin/localkube {{.Flags}} --generate-certs=false --logtostderr=true --enable-dns=false --node-ip={{.NodeIP}}"
|
||||
var localkubeStartCmdTemplate = "/usr/local/bin/localkube {{.Flags}} --generate-certs=false --logtostderr=true --enable-dns=false --node-ip={{.NodeIP}} --apiserver-name={{.APIServerName}}"
|
||||
|
||||
var startCommandB2DTemplate = `
|
||||
# Run with nohup so it stays up. Redirect logs to useful places.
|
||||
|
@ -162,11 +162,13 @@ func GenLocalkubeStartCmd(kubernetesConfig KubernetesConfig) (string, error) {
|
|||
t := template.Must(template.New("localkubeStartCmd").Parse(localkubeStartCmdTemplate))
|
||||
buf := bytes.Buffer{}
|
||||
data := struct {
|
||||
Flags string
|
||||
NodeIP string
|
||||
Flags string
|
||||
NodeIP string
|
||||
APIServerName string
|
||||
}{
|
||||
Flags: flags,
|
||||
NodeIP: kubernetesConfig.NodeIP,
|
||||
Flags: flags,
|
||||
NodeIP: kubernetesConfig.NodeIP,
|
||||
APIServerName: kubernetesConfig.APIServerName,
|
||||
}
|
||||
if err := t.Execute(&buf, data); err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -28,9 +28,9 @@ var (
|
|||
internalIP = net.ParseIP(util.DefaultServiceClusterIP)
|
||||
)
|
||||
|
||||
func GenerateCerts(caCert, caKey, pub, priv string, ip net.IP) error {
|
||||
func GenerateCerts(caCert, caKey, pub, priv string, ip net.IP, name string) error {
|
||||
if !(util.CanReadFile(caCert) && util.CanReadFile(caKey)) {
|
||||
if err := util.GenerateCACert(caCert, caKey); err != nil {
|
||||
if err := util.GenerateCACert(caCert, caKey, name); err != nil {
|
||||
return errors.Wrap(err, "Error generating certificate")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ type MachineConfig struct {
|
|||
type KubernetesConfig struct {
|
||||
KubernetesVersion string
|
||||
NodeIP string
|
||||
APIServerName string
|
||||
ContainerRuntime string
|
||||
NetworkPlugin string
|
||||
FeatureGates string
|
||||
|
|
|
@ -31,7 +31,10 @@ import (
|
|||
const MachineName = "minikube"
|
||||
|
||||
// APIServerPort is the port that the API server should listen on.
|
||||
const APIServerPort = 8443
|
||||
const (
|
||||
APIServerPort = 8443
|
||||
APIServerName = "minikubeCA"
|
||||
)
|
||||
|
||||
const MinikubeHome = "MINIKUBE_HOME"
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func GenerateCACert(certPath, keyPath string) error {
|
||||
func GenerateCACert(certPath, keyPath string, name string) error {
|
||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error generating rsa key")
|
||||
|
@ -42,7 +42,7 @@ func GenerateCACert(certPath, keyPath string) error {
|
|||
template := x509.Certificate{
|
||||
SerialNumber: big.NewInt(1),
|
||||
Subject: pkix.Name{
|
||||
CommonName: "minikubeCA",
|
||||
CommonName: name,
|
||||
},
|
||||
NotBefore: time.Now(),
|
||||
NotAfter: time.Now().Add(time.Hour * 24 * 365 * 10),
|
||||
|
|
|
@ -24,6 +24,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/constants"
|
||||
)
|
||||
|
||||
func TestGenerateCACert(t *testing.T) {
|
||||
|
@ -35,7 +37,7 @@ func TestGenerateCACert(t *testing.T) {
|
|||
|
||||
certPath := filepath.Join(tmpDir, "cert")
|
||||
keyPath := filepath.Join(tmpDir, "key")
|
||||
if err := GenerateCACert(certPath, keyPath); err != nil {
|
||||
if err := GenerateCACert(certPath, keyPath, constants.APIServerName); err != nil {
|
||||
t.Fatalf("GenerateCACert() error = %v", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue