Skip to content

Commit

Permalink
Feature/sandbox k8s manifest (#30)
Browse files Browse the repository at this point in the history
* Add kubernetes manifest

Signed-off-by: S-mishina <[email protected]>

* fix Kubernetes deeployment image tag & Add README.md

Signed-off-by: S-mishina <[email protected]>

* fix README.md

Signed-off-by: S-mishina <[email protected]>

---------

Signed-off-by: S-mishina <[email protected]>
  • Loading branch information
S-mishina authored Sep 14, 2024
1 parent f72eda4 commit 20908ac
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 5 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ This is a mock server used to verify the operation of service mesh tools. Servic

## usage rules

* docker

```:terminal
docker run -p 8080:8080 ghcr.io/s-mishina/flexiblemockserver:latest
```
[usage rules README](./sample_manifest/README.md)

## Example

Expand Down
103 changes: 103 additions & 0 deletions sample_manifest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# intro

## Docker

```:terminal
docker run -p 8080:8080 ghcr.io/s-mishina/flexiblemockserver:latest
```

Currently, it will not work unless the custom rule file exists.

## Docker-Compose

## Kubernetes

To use flexiblemockserver on Kubernetes, please follow the steps below.
This document describes how to use [kind](https://kind.sigs.k8s.io/).

### step 1

Create a cluster using kind.

sample command

```:terminal
flexiblemockserver/sample_manifest/kubernetes(ap-northeast-1)
❯ ls
cluster.yaml flexiblemockserver
```

```:terminal
❯ kind create cluster -n sandbox-test --config cluster.yaml
Creating cluster "sandbox-test" ...
✓ Ensuring node image (kindest/node:v1.27.3) 🖼
✓ Preparing nodes 📦 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-sandbox-test"
You can now use your cluster with:
kubectl cluster-info --context kind-sandbox-test
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂
```

### step 2

Please import the required IMAGE onto kind.

sample command

```:terminal
❯ docker pull ghcr.io/s-mishina/flexiblemockserver:latest
```

```:terminal
❯ kind load docker-image ghcr.io/s-mishina/flexiblemockserver:latest ghcr.io/s-mishina/flexiblemockserver:latest -n sandbox-test
Image: "ghcr.io/s-mishina/flexiblemockserver:latest" with ID "sha256:96b36be4d13881b2567a42662dd3a613649740348d0a360d0b686b7eb4c7798e" not yet present on node "sandbox-test-worker2", loading...
Image: "ghcr.io/s-mishina/flexiblemockserver:latest" with ID "sha256:96b36be4d13881b2567a42662dd3a613649740348d0a360d0b686b7eb4c7798e" not yet present on node "sandbox-test-worker3", loading...
Image: "ghcr.io/s-mishina/flexiblemockserver:latest" with ID "sha256:96b36be4d13881b2567a42662dd3a613649740348d0a360d0b686b7eb4c7798e" not yet present on node "sandbox-test-control-plane", loading...
Image: "ghcr.io/s-mishina/flexiblemockserver:latest" with ID "sha256:96b36be4d13881b2567a42662dd3a613649740348d0a360d0b686b7eb4c7798e" not yet present on node "sandbox-test-worker", loading...
```

### step 3

Finally, let's apply the manifest!

```:terminal
[kind-sandbox-test|default] :ctx
[arm64]⚡️
flexiblemockserver/sample_manifest/kubernetes on  feature/sandbox-k8s-manifest
❯ ls
cluster.yaml flexiblemockserver
[kind-sandbox-test|default] :ctx
[arm64]⚡️
flexiblemockserver/sample_manifest/kubernetes on  feature/sandbox-k8s-manifest
❯ kubectl apply -k flexiblemockserver
namespace/mockserver created
configmap/custom-rule created
configmap/response created
service/flexiblemockserver created
deployment.apps/flexiblemockserver created
```

### as necessary

This document is intended to confirm the operation of ServiceMesh and Kuberneres.

The following custom operator

#### Reloader

[document](https://github.com/stakater/Reloader?tab=readme-ov-file#vanilla-manifests)

#### istio

[document](https://istio.io/latest/docs/setup/install/istioctl/)


Empty file.
8 changes: 8 additions & 0 deletions sample_manifest/kubernetes/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
42 changes: 42 additions & 0 deletions sample_manifest/kubernetes/flexiblemockserver/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: custom-rule
namespace: mockserver
annotations:
reloader.stakater.com/match: "true"
data:
custom_rule.yaml: |
custom_rule:
- name: "Custom Rule"
rule:
path: "/example"
method: "GET"
status_code: 200
response_body_path: "config/json/response1.json"
- name: "liveness"
rule:
path: "/liveness"
method: "GET"
status_code: 200
response_body_path: "config/json/response1.json"
- name: "readiness"
rule:
path: "/readiness"
method: "GET"
status_code: 200
response_body_path: "config/json/response1.json"
# ref: https://github.com/S-mishina/flexiblemockserver?tab=readme-ov-file#custom-rule
---
# configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: response
namespace: test
annotations:
reloader.stakater.com/match: "true"
data:
response1.json: |
{"response","Hello, World!"}
59 changes: 59 additions & 0 deletions sample_manifest/kubernetes/flexiblemockserver/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: flexiblemockserver
namespace: mockserver
annotations:
configmap.reloader.stakater.com/reload: "*"
spec:
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 0
replicas: 4
selector:
matchLabels:
app: flexiblemockserver
template:
metadata:
labels:
app: flexiblemockserver
istio-injection: enabled
test: "test4"

spec:
containers:
- name: flexiblemockserver
image: ghcr.io/s-mishina/flexiblemockserver:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: CUSTOM_RULE_YAML_FILE
value: config/custom_rule.yaml
volumeMounts:
- name: custom-rule
mountPath: /config
- name: response
mountPath: /config/json
volumes:
- name: custom-rule
configMap:
name: custom-rule
- name: response
configMap:
name: response
# TODO: Set if Liveness rediness is required.
# readinessProbe:
# httpGet:
# path: /readiness
# port: 8080
# periodSeconds: 1
# failureThreshold: 1
# livenessProbe:
# httpGet:
# path: /liveness
# port: 8080
# periodSeconds: 1
# failureThreshold: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# kustmize.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: mockserver
resources:
- deployment.yaml
- configmap.yaml
- service.yaml
- namespace.yaml
7 changes: 7 additions & 0 deletions sample_manifest/kubernetes/flexiblemockserver/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: mockserver
labels:
istio-injection: enabled
13 changes: 13 additions & 0 deletions sample_manifest/kubernetes/flexiblemockserver/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: flexiblemockserver
namespace: mockserver
spec:
selector:
app: flexiblemockserver
ports:
- protocol: TCP
port: 80
targetPort: 8080

0 comments on commit 20908ac

Please sign in to comment.