diff --git a/controllers/nginx/README.md b/controllers/nginx/README.md index 763dd50b8..8a527e37f 100644 --- a/controllers/nginx/README.md +++ b/controllers/nginx/README.md @@ -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) +## 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 diff --git a/controllers/nginx/main.go b/controllers/nginx/main.go index ed6f7539a..922ab9f31 100644 --- a/controllers/nginx/main.go +++ b/controllers/nginx/main.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "flag" "fmt" "net/http" "net/http/pprof" @@ -34,6 +33,7 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/healthz" + kubectl_util "k8s.io/kubernetes/pkg/kubectl/cmd/util" ) const ( @@ -55,16 +55,20 @@ var ( nxgConfigMap = flags.String("nginx-configmap", "", `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", "", `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 name of the port. The ports 80 and 443 are not allowed as external ports. This ports are reserved for nginx`) udpConfigMapName = flags.String("udp-services-configmap", "", `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 name of the port.`) @@ -83,8 +87,9 @@ var ( ) func main() { - flags.AddGoFlagSet(flag.CommandLine) + var kubeClient *unversioned.Client flags.Parse(os.Args) + clientConfig := kubectl_util.DefaultClientConfig(flags) glog.Infof("Using build: %v - %v", gitRepo, version) @@ -94,25 +99,36 @@ func main() { } 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 { glog.Fatalf("failed to create client: %v", err) } - podInfo, err := getPodDetails(kubeClient) - if err != nil { - glog.Fatalf("unexpected error getting runtime information: %v", err) + runtimePodInfo := &podInfo{NodeIP: "127.0.0.1"} + if *inCluster { + runtimePodInfo, err = getPodDetails(kubeClient) + if err != nil { + glog.Fatalf("unexpected error getting runtime information: %v", err) + } } - - err = isValidService(kubeClient, *defaultSvc) - if err != nil { + if err := isValidService(kubeClient, *defaultSvc); err != nil { 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 { glog.Fatalf("%v", err) } diff --git a/controllers/nginx/nginx/main.go b/controllers/nginx/nginx/main.go index 706fde77b..66c702c89 100644 --- a/controllers/nginx/nginx/main.go +++ b/controllers/nginx/nginx/main.go @@ -294,6 +294,10 @@ func NewManager(kubeClient *client.Client) *Manager { func (nginx *Manager) createCertsDir(base string) { 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) } } diff --git a/controllers/nginx/rc.yaml b/controllers/nginx/rc.yaml index f6a254c2b..8c1beff6f 100644 --- a/controllers/nginx/rc.yaml +++ b/controllers/nginx/rc.yaml @@ -80,10 +80,6 @@ spec: timeoutSeconds: 5 # use downward API env: - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - name: POD_NAME valueFrom: fieldRef: