mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-16 15:38:40 +00:00
TRA-3913 support mizu via expose service (#440)
* Update README.md, tapRunner.go, and 4 more files... * Update testsUtils.go * Update proxy.go * Update README.md, testsUtils.go, and 3 more files... * Update testsUtils.go and provider.go
This commit is contained in:
parent
b7b012539d
commit
4cf3c9c6d3
48
README.md
48
README.md
@ -83,7 +83,7 @@ To tap all pods in current namespace -
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
To tap specific pod -
|
###To tap specific pod
|
||||||
```bash
|
```bash
|
||||||
$ kubectl get pods
|
$ kubectl get pods
|
||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
@ -96,7 +96,7 @@ To tap specific pod -
|
|||||||
^C
|
^C
|
||||||
```
|
```
|
||||||
|
|
||||||
To tap multiple pods using regex -
|
###To tap multiple pods using regex
|
||||||
```bash
|
```bash
|
||||||
$ kubectl get pods
|
$ kubectl get pods
|
||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
@ -111,6 +111,50 @@ To tap multiple pods using regex -
|
|||||||
Web interface is now available at http://localhost:8899
|
Web interface is now available at http://localhost:8899
|
||||||
^C
|
^C
|
||||||
```
|
```
|
||||||
|
###To run mizu mizu daemon mode (detached from cli)
|
||||||
|
```bash
|
||||||
|
$ mizu tap "^ca.*" --daemon
|
||||||
|
Mizu will store up to 200MB of traffic, old traffic will be cleared once the limit is reached.
|
||||||
|
Tapping pods in namespaces "sock-shop"
|
||||||
|
Waiting for mizu to be ready... (may take a few minutes)
|
||||||
|
+carts-66c77f5fbb-fq65r
|
||||||
|
+catalogue-5f4cb7cf5-7zrmn
|
||||||
|
..
|
||||||
|
|
||||||
|
$ mizu view
|
||||||
|
Establishing connection to k8s cluster...
|
||||||
|
Mizu is available at http://localhost:8899
|
||||||
|
^C
|
||||||
|
..
|
||||||
|
|
||||||
|
$ mizu clean # mizu will continue running in cluster until clean is executed
|
||||||
|
Removing mizu resources
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###To run mizu daemon mode with LoadBalancer kubernetes service
|
||||||
|
```bash
|
||||||
|
$ mizu tap "^ca.*" --daemon
|
||||||
|
Mizu will store up to 200MB of traffic, old traffic will be cleared once the limit is reached.
|
||||||
|
Tapping pods in namespaces "sock-shop"
|
||||||
|
Waiting for mizu to be ready... (may take a few minutes)
|
||||||
|
..
|
||||||
|
|
||||||
|
$ kubectl expose deployment -n mizu --port 80 --target-port 8899 mizu-api-server --type=LoadBalancer --name=mizu-lb
|
||||||
|
service/mizu-lb exposed
|
||||||
|
..
|
||||||
|
|
||||||
|
$ kubectl get services -n mizu
|
||||||
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||||
|
mizu-api-server ClusterIP 10.107.200.100 <none> 80/TCP 5m5s
|
||||||
|
mizu-lb LoadBalancer 10.107.200.101 34.77.120.116 80:30141/TCP 76s
|
||||||
|
```
|
||||||
|
Note that `LoadBalancer` services only work on supported clusters (usually cloud providers) and might incur extra costs
|
||||||
|
|
||||||
|
If you changed the `mizu-resources-namespace` value, make sure the `-n mizu` flag of the `kubectl expose` command is changed to the value of `mizu-resources-namespace`
|
||||||
|
|
||||||
|
mizu will now be available both by running `mizu view` or by accessing the `EXTERNAL-IP` of the `mizu-lb` service through your browser.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ func getProxyUrl(namespace string, service string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getApiServerUrl(port uint16) string {
|
func getApiServerUrl(port uint16) string {
|
||||||
return fmt.Sprintf("http://localhost:%v/mizu", port)
|
return fmt.Sprintf("http://localhost:%v", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultCommandArgs() []string {
|
func getDefaultCommandArgs() []string {
|
||||||
|
@ -320,7 +320,6 @@ func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, moun
|
|||||||
return pod, nil
|
return pod, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (provider *Provider) CreatePod(ctx context.Context, namespace string, podSpec *core.Pod) (*core.Pod, error) {
|
func (provider *Provider) CreatePod(ctx context.Context, namespace string, podSpec *core.Pod) (*core.Pod, error) {
|
||||||
return provider.clientSet.CoreV1().Pods(namespace).Create(ctx, podSpec, metav1.CreateOptions{})
|
return provider.clientSet.CoreV1().Pods(namespace).Create(ctx, podSpec, metav1.CreateOptions{})
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@ func StartProxy(kubernetesProvider *Provider, proxyHost string, mizuPort uint16,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle(k8sProxyApiPrefix, proxyHandler)
|
mux.Handle(k8sProxyApiPrefix, getRerouteHttpHandlerMizuAPI(proxyHandler, mizuNamespace, mizuServiceName))
|
||||||
mux.Handle("/static/", getRerouteHttpHandlerMizuStatic(proxyHandler, mizuNamespace, mizuServiceName))
|
mux.Handle("/static/", getRerouteHttpHandlerMizuStatic(proxyHandler, mizuNamespace, mizuServiceName))
|
||||||
mux.Handle("/mizu/", getRerouteHttpHandlerMizuAPI(proxyHandler, mizuNamespace, mizuServiceName))
|
|
||||||
|
|
||||||
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", proxyHost, int(mizuPort)))
|
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", proxyHost, int(mizuPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -45,16 +45,21 @@ func StartProxy(kubernetesProvider *Provider, proxyHost string, mizuPort uint16,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMizuApiServerProxiedHostAndPath(mizuNamespace string, mizuServiceName string) string {
|
func getMizuApiServerProxiedHostAndPath(mizuNamespace string, mizuServiceName string) string {
|
||||||
return fmt.Sprintf("/api/v1/namespaces/%s/services/%s:%d/proxy/", mizuNamespace, mizuServiceName, mizuServicePort)
|
return fmt.Sprintf("/api/v1/namespaces/%s/services/%s:%d/proxy", mizuNamespace, mizuServiceName, mizuServicePort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMizuApiServerProxiedHostAndPath(mizuPort uint16) string {
|
func GetMizuApiServerProxiedHostAndPath(mizuPort uint16) string {
|
||||||
return fmt.Sprintf("localhost:%d/mizu", mizuPort)
|
return fmt.Sprintf("localhost:%d", mizuPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRerouteHttpHandlerMizuAPI(proxyHandler http.Handler, mizuNamespace string, mizuServiceName string) http.Handler {
|
func getRerouteHttpHandlerMizuAPI(proxyHandler http.Handler, mizuNamespace string, mizuServiceName string) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
r.URL.Path = strings.Replace(r.URL.Path, "/mizu/", getMizuApiServerProxiedHostAndPath(mizuNamespace, mizuServiceName), 1)
|
proxiedPath := getMizuApiServerProxiedHostAndPath(mizuNamespace, mizuServiceName)
|
||||||
|
|
||||||
|
//avoid redirecting several times
|
||||||
|
if !strings.Contains(r.URL.Path, proxiedPath) {
|
||||||
|
r.URL.Path = fmt.Sprintf("%s%s", getMizuApiServerProxiedHostAndPath(mizuNamespace, mizuServiceName), r.URL.Path)
|
||||||
|
}
|
||||||
proxyHandler.ServeHTTP(w, r)
|
proxyHandler.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
import * as axios from "axios";
|
import * as axios from "axios";
|
||||||
|
|
||||||
const mizuAPIPathPrefix = "/mizu";
|
|
||||||
|
|
||||||
// When working locally cp `cp .env.example .env`
|
// When working locally cp `cp .env.example .env`
|
||||||
export const MizuWebsocketURL = process.env.REACT_APP_OVERRIDE_WS_URL ? process.env.REACT_APP_OVERRIDE_WS_URL : `ws://${window.location.host}${mizuAPIPathPrefix}/ws`;
|
export const MizuWebsocketURL = process.env.REACT_APP_OVERRIDE_WS_URL ? process.env.REACT_APP_OVERRIDE_WS_URL : `ws://${window.location.host}/ws`;
|
||||||
|
|
||||||
export default class Api {
|
export default class Api {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
// When working locally cp `cp .env.example .env`
|
// When working locally cp `cp .env.example .env`
|
||||||
const apiURL = process.env.REACT_APP_OVERRIDE_API_URL ? process.env.REACT_APP_OVERRIDE_API_URL : `${window.location.origin}${mizuAPIPathPrefix}/`;
|
const apiURL = process.env.REACT_APP_OVERRIDE_API_URL ? process.env.REACT_APP_OVERRIDE_API_URL : `${window.location.origin}/`;
|
||||||
|
|
||||||
this.client = axios.create({
|
this.client = axios.create({
|
||||||
baseURL: apiURL,
|
baseURL: apiURL,
|
||||||
|
Loading…
Reference in New Issue
Block a user