Add running-in-cluster=false option.
This commit is contained in:
parent
b7e8109a6d
commit
5c8a25c833
4 changed files with 43 additions and 17 deletions
|
@ -18,6 +18,16 @@ This is a nginx Ingress controller that uses [ConfigMap](https://github.com/kube
|
||||||
- default backend [404-server](https://github.com/kubernetes/contrib/tree/master/404-server)
|
- default backend [404-server](https://github.com/kubernetes/contrib/tree/master/404-server)
|
||||||
|
|
||||||
|
|
||||||
|
## Dry running the Ingress controller
|
||||||
|
|
||||||
|
Before deploying the controller to production you might want to run it outside the cluster and observe it.
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ make controller
|
||||||
|
$ mkdir /etc/nginx-ssl
|
||||||
|
$ ./nginx-ingress-controller --running-in-cluster=false --default-backend-service=kube-system/default-http-backend
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Deploy the Ingress controller
|
## Deploy the Ingress controller
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
"net/http/pprof"
|
||||||
|
@ -34,6 +33,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned"
|
"k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/healthz"
|
"k8s.io/kubernetes/pkg/healthz"
|
||||||
|
kubectl_util "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -55,16 +55,20 @@ var (
|
||||||
nxgConfigMap = flags.String("nginx-configmap", "",
|
nxgConfigMap = flags.String("nginx-configmap", "",
|
||||||
`Name of the ConfigMap that containes the custom nginx configuration to use`)
|
`Name of the ConfigMap that containes the custom nginx configuration to use`)
|
||||||
|
|
||||||
|
inCluster = flags.Bool("running-in-cluster", true,
|
||||||
|
`Optional, if this controller is running in a kubernetes cluster, use the
|
||||||
|
pod secrets for creating a Kubernetes client.`)
|
||||||
|
|
||||||
tcpConfigMapName = flags.String("tcp-services-configmap", "",
|
tcpConfigMapName = flags.String("tcp-services-configmap", "",
|
||||||
`Name of the ConfigMap that containes the definition of the TCP services to expose.
|
`Name of the ConfigMap that containes the definition of the TCP services to expose.
|
||||||
The key in the map indicates the external port to be used. The value is the name of the
|
The key in the map indicates the external port to be used. The value is the name of the
|
||||||
service with the format namespace/serviceName and the port of the service could be a number of the
|
service with the format namespace/serviceName and the port of the service could be a number of the
|
||||||
name of the port.
|
name of the port.
|
||||||
The ports 80 and 443 are not allowed as external ports. This ports are reserved for nginx`)
|
The ports 80 and 443 are not allowed as external ports. This ports are reserved for nginx`)
|
||||||
|
|
||||||
udpConfigMapName = flags.String("udp-services-configmap", "",
|
udpConfigMapName = flags.String("udp-services-configmap", "",
|
||||||
`Name of the ConfigMap that containes the definition of the UDP services to expose.
|
`Name of the ConfigMap that containes the definition of the UDP services to expose.
|
||||||
The key in the map indicates the external port to be used. The value is the name of the
|
The key in the map indicates the external port to be used. The value is the name of the
|
||||||
service with the format namespace/serviceName and the port of the service could be a number of the
|
service with the format namespace/serviceName and the port of the service could be a number of the
|
||||||
name of the port.`)
|
name of the port.`)
|
||||||
|
|
||||||
|
@ -83,8 +87,9 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flags.AddGoFlagSet(flag.CommandLine)
|
var kubeClient *unversioned.Client
|
||||||
flags.Parse(os.Args)
|
flags.Parse(os.Args)
|
||||||
|
clientConfig := kubectl_util.DefaultClientConfig(flags)
|
||||||
|
|
||||||
glog.Infof("Using build: %v - %v", gitRepo, version)
|
glog.Infof("Using build: %v - %v", gitRepo, version)
|
||||||
|
|
||||||
|
@ -94,25 +99,36 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *defaultSvc == "" {
|
if *defaultSvc == "" {
|
||||||
glog.Fatalf("Please specify --default-backend")
|
glog.Fatalf("Please specify --default-backend-service")
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeClient, err := unversioned.NewInCluster()
|
var err error
|
||||||
|
if *inCluster {
|
||||||
|
kubeClient, err = unversioned.NewInCluster()
|
||||||
|
} else {
|
||||||
|
config, connErr := clientConfig.ClientConfig()
|
||||||
|
if connErr != nil {
|
||||||
|
glog.Fatalf("error connecting to the client: %v", err)
|
||||||
|
}
|
||||||
|
kubeClient, err = unversioned.New(config)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("failed to create client: %v", err)
|
glog.Fatalf("failed to create client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
podInfo, err := getPodDetails(kubeClient)
|
runtimePodInfo := &podInfo{NodeIP: "127.0.0.1"}
|
||||||
if err != nil {
|
if *inCluster {
|
||||||
glog.Fatalf("unexpected error getting runtime information: %v", err)
|
runtimePodInfo, err = getPodDetails(kubeClient)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("unexpected error getting runtime information: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if err := isValidService(kubeClient, *defaultSvc); err != nil {
|
||||||
err = isValidService(kubeClient, *defaultSvc)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatalf("no service with name %v found: %v", *defaultSvc, err)
|
glog.Fatalf("no service with name %v found: %v", *defaultSvc, err)
|
||||||
}
|
}
|
||||||
|
glog.Infof("Validated %v as the default backend", *defaultSvc)
|
||||||
|
|
||||||
lbc, err := newLoadBalancerController(kubeClient, *resyncPeriod, *defaultSvc, *watchNamespace, *nxgConfigMap, *tcpConfigMapName, *udpConfigMapName, podInfo)
|
lbc, err := newLoadBalancerController(kubeClient, *resyncPeriod, *defaultSvc, *watchNamespace, *nxgConfigMap, *tcpConfigMapName, *udpConfigMapName, runtimePodInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("%v", err)
|
glog.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,6 +294,10 @@ func NewManager(kubeClient *client.Client) *Manager {
|
||||||
|
|
||||||
func (nginx *Manager) createCertsDir(base string) {
|
func (nginx *Manager) createCertsDir(base string) {
|
||||||
if err := os.Mkdir(base, os.ModeDir); err != nil {
|
if err := os.Mkdir(base, os.ModeDir); err != nil {
|
||||||
|
if os.IsExist(err) {
|
||||||
|
glog.Infof("%v already exists", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
glog.Fatalf("Couldn't create directory %v: %v", base, err)
|
glog.Fatalf("Couldn't create directory %v: %v", base, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,10 +80,6 @@ spec:
|
||||||
timeoutSeconds: 5
|
timeoutSeconds: 5
|
||||||
# use downward API
|
# use downward API
|
||||||
env:
|
env:
|
||||||
- name: POD_IP
|
|
||||||
valueFrom:
|
|
||||||
fieldRef:
|
|
||||||
fieldPath: status.podIP
|
|
||||||
- name: POD_NAME
|
- name: POD_NAME
|
||||||
valueFrom:
|
valueFrom:
|
||||||
fieldRef:
|
fieldRef:
|
||||||
|
|
Loading…
Reference in a new issue