-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from johnsonj/kubeproxy
kubeproxy operator
- Loading branch information
Showing
51 changed files
with
2,564 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
bin | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Kubernetes Generated files - skip generated files, except for vendored files | ||
|
||
!vendor/**/zz_generated.* | ||
|
||
# editor and IDE paraphernalia | ||
.idea | ||
*.swp | ||
*.swo | ||
*~ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM ubuntu:latest as kubectl | ||
RUN apt-get update | ||
RUN apt-get install curl -y | ||
RUN curl -fsSL https://dl.k8s.io/release/v1.17.4/bin/linux/amd64/kubectl > /usr/bin/kubectl | ||
RUN chmod a+rx /usr/bin/kubectl | ||
# Build the manager binary | ||
FROM golang:1.13 as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY main.go main.go | ||
COPY api/ api/ | ||
COPY controllers/ controllers/ | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go | ||
|
||
# Use distroless as minimal base image to package the manager binary | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM gcr.io/distroless/static:nonroot | ||
WORKDIR / | ||
COPY --from=builder /workspace/manager . | ||
COPY --from=kubectl /usr/bin/kubectl /usr/bin/kubectl | ||
COPY channels/ channels/ | ||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["/manager"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
all: manager | ||
|
||
# Run tests | ||
test: generate fmt vet manifests | ||
go test ./... -coverprofile cover.out | ||
|
||
# Build manager binary | ||
manager: generate fmt vet | ||
go build -o bin/manager main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: generate fmt vet manifests | ||
go run ./main.go | ||
|
||
# Install CRDs into a cluster | ||
install: manifests | ||
kustomize build config/crd | kubectl apply -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: manifests | ||
cd config/manager && kustomize edit set image controller=${IMG} | ||
kustomize build config/default | kubectl apply -f - | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Run go fmt against code | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
vet: | ||
go vet ./... | ||
|
||
# Generate code | ||
generate: controller-gen | ||
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..." | ||
|
||
# Build the docker image | ||
docker-build: test | ||
docker build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
controller-gen: | ||
ifeq (, $(shell which controller-gen)) | ||
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.1 | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: "2" | ||
domain: x-k8s.io | ||
repo: addon-operators/kubeproxy | ||
resources: | ||
- group: addons | ||
version: v1alpha1 | ||
kind: KubeProxy |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# kubeproxy-operator | ||
|
||
kubeproxy-operator is a Kubernetes operator for managing kubeproxy. | ||
|
||
## Running in a cluster | ||
|
||
1. Create a kinder cluster | ||
Ensure kinder is installed. [Installation docs](https://github.com/kubernetes/kubeadm/blob/master/kinder/README.md) | ||
|
||
```bash | ||
kinder create cluster --image=kindest/node:v1.18.0 | ||
|
||
kinder do kubeadm-config | ||
kinder do loadbalancer | ||
|
||
docker exec -it kind-control-plane-1 /kind/bin/kubeadm init --skip-phases="addon/kube-proxy" --ignore-preflight-errors="FileContent--proc-sys-net-bridge-bridge-nf-call-iptables,Swap,SystemVerification" --config /kind/kubeadm.conf | ||
kinder exec @all -- sysctl -w net.ipv4.conf.all.rp_filter=1 | ||
|
||
kinder cp @cp1:/etc/kubernetes/admin.conf $(kinder get kubeconfig-path) | ||
export KUBECONFIG=$(kinder get kubeconfig-path) | ||
``` | ||
|
||
You might have set the server ip in the KUBECONFIG to use localhost to reach the cluster, you will have to set the server to `localhost`. To find the port, run `docker inspect kind-control-plane-1 -f '{{(index (index .NetworkSettings.Ports "6443/tcp") 0).HostPort}}'` and check the port | ||
|
||
Edit your KUBECONFIG `vi $KUBECONFIG` | ||
```yaml | ||
server: https://localhost:<port> | ||
``` | ||
|
||
2. Set the Kubernetes Service host and port in manager.yaml ssh into the node and get the host and port. The command below should give the host. | ||
|
||
```bash | ||
docker inspect kind-control-plane-1 | grep IPAddress | ||
``` | ||
|
||
Edit `config/manager/patches/apiserver_endpoint.path.yaml` | ||
|
||
```yaml | ||
- name: KUBERNETES_SERVICE_HOST | ||
value: <your-kubernetes-ip> | ||
- name: KUBERNETES_SERVICE_PORT | ||
value: <your-kubernetes-port> | ||
``` | ||
|
||
|
||
3. Build and deploy Docker image | ||
|
||
```bash | ||
make docker-build | ||
make deploy | ||
``` | ||
|
||
4. Install CRD | ||
|
||
```bash | ||
make install | ||
kubectl apply -f config/samples/ | ||
``` | ||
|
||
5. KubeProxy should be up and running | ||
|
||
```bash | ||
kubectl get kubeproxy -n kube-system | ||
kubectl get daemonset -n kube-system kubeproxy | ||
kubectl get nodes | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1alpha1 contains API Schema definitions for the addons v1alpha1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=addons.x-k8s.io | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "addons.x-k8s.io", Version: "v1alpha1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1" | ||
) | ||
|
||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
||
// KubeProxySpec defines the desired state of KubeProxy | ||
type KubeProxySpec struct { | ||
addonv1alpha1.CommonSpec `json:",inline"` | ||
addonv1alpha1.PatchSpec `json:",inline"` | ||
|
||
ClusterCIDR string `json:"clusterCidr,omitempty"` | ||
} | ||
|
||
// KubeProxyStatus defines the observed state of KubeProxy | ||
type KubeProxyStatus struct { | ||
addonv1alpha1.CommonStatus `json:",inline"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// KubeProxy is the Schema for the API | ||
type KubeProxy struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec KubeProxySpec `json:"spec,omitempty"` | ||
Status KubeProxyStatus `json:"status,omitempty"` | ||
} | ||
|
||
var _ addonv1alpha1.CommonObject = &KubeProxy{} | ||
|
||
func (o *KubeProxy) ComponentName() string { | ||
return "kubeproxy" | ||
} | ||
|
||
func (o *KubeProxy) CommonSpec() addonv1alpha1.CommonSpec { | ||
return o.Spec.CommonSpec | ||
} | ||
|
||
func (o *KubeProxy) PatchSpec() addonv1alpha1.PatchSpec { | ||
return o.Spec.PatchSpec | ||
} | ||
|
||
func (o *KubeProxy) GetCommonStatus() addonv1alpha1.CommonStatus { | ||
return o.Status.CommonStatus | ||
} | ||
|
||
func (o *KubeProxy) SetCommonStatus(s addonv1alpha1.CommonStatus) { | ||
o.Status.CommonStatus = s | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// KubeProxyList contains a list of KubeProxy | ||
type KubeProxyList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []KubeProxy `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&KubeProxy{}, &KubeProxyList{}) | ||
} |
Oops, something went wrong.