Skip to content

Commit

Permalink
http-service: k8s deploy support (pingcap#5323)
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc authored Oct 11, 2023
1 parent b2cb233 commit 45cd55c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cmd/http-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM pingcap/pingcap-base:v1

ARG TARGETARCH
RUN dnf install -y tzdata bind-utils && dnf clean all
ADD bin/${TARGETARCH}/http-service /usr/local/bin/http-service

CMD ["/usr/local/bin/http-service"]
10 changes: 9 additions & 1 deletion cmd/http-service/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ LDFLAGS += -X "github.com/pingcap/tidb-operator/http-service/version.GitBranch=$
LDFLAGS += -X "github.com/pingcap/tidb-operator/http-service/version.GoVersion=$(shell go version)"

GO := $(GOENV) go
GOARCH ?= $(shell go env GOARCH)
GOBUILD := CGO_ENABLED=0 $(GO) build

DOCKER_REGISTRY ?= localhost:5000
DOCKER_REPO ?= ${DOCKER_REGISTRY}/pingcap
IMAGE_TAG ?= latest

build:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/http-service .
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/$(GOARCH)/http-service .

docker: build
docker build --tag "${DOCKER_REPO}/tidb-operator-http-service:${IMAGE_TAG}" --build-arg=TARGETARCH=$(GOARCH) .

buf:
GOBIN=$(shell pwd)/bin/ $(GO) install github.com/bufbuild/buf/cmd/[email protected]
Expand Down
4 changes: 3 additions & 1 deletion cmd/http-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ run `make buf-generate`

### Build

run `make build`
- run `make build` to build a binary
- run `make image` to build a Docker image

## Run

- When running the binary out of a Kubernetes cluster, the `--kubeconfig` must be set to a KUBECONFIG file path.
- The context name in the KUBECONFIG should be used as the `kubernetes-id` in the HTTP header.
- Try to apply the `./deploy.yaml` for a Kubernetes cluster.
- If the Kubernetes cluster does not have enough resources, set `LOCAL_RUN=true` environment variable when running the binary.
- This will let this HTTP Service to remove the CPU & memory requests for components so that Pods can be scheduled.

Expand Down
67 changes: 67 additions & 0 deletions cmd/http-service/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
kind: ServiceAccount
apiVersion: v1
metadata:
name: tidb-operator-http-service
namespace: tidb-admin
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tidb-operator:http-service
rules:
- apiGroups: ["*"]
resources: ["namespaces", "secrets"]
verbs: ["*"]
- apiGroups: ["pingcap.com"]
resources: ["*"]
verbs: ["*"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: tidb-operator:http-service
subjects:
- kind: ServiceAccount
name: tidb-operator-http-service
namespace: tidb-admin
roleRef:
kind: ClusterRole
name: tidb-operator:http-service
apiGroup: rbac.authorization.k8s.io
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: tidb-operator-http-service
namespace: tidb-admin
labels:
app: tidb-operator-http-service
spec:
replicas: 1
selector:
matchLabels:
app: tidb-operator-http-service
template:
metadata:
labels:
app: tidb-operator-http-service
spec:
serviceAccountName: tidb-operator-http-service
containers:
- name: http-service
image: pingcap/tidb-operator-http-service:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
kind: Service
apiVersion: v1
metadata:
name: tidb-operator-http-service
namespace: tidb-admin
spec:
ports:
- port: 9080
targetPort: 9080
selector:
app: tidb-operator-http-service

0 comments on commit 45cd55c

Please sign in to comment.