Skip to content

Commit 78f205d

Browse files
authored
Fix getting-started guide: Use full paths for YAML files and correct kubeconfig references (#1451)
* Update getting-started.md to use full paths for YAML files and correct kubeconfig Update all YAML file references to use full relative paths from repository root: - examples/multitenancy/hello-world/hello-world-service-composition.yaml - examples/multitenancy/hello-world/hs1.yaml - examples/multitenancy/hello-world/hs2.yaml - examples/multitenancy/hello-world/hs1-no-replicas.yaml - examples/multitenancy/hello-world/hs2-no-replicas.yaml Update all kubeconfig references to use kubeplus-saas-provider.json (the actual file created by provider-kubeconfig.py in the root directory) instead of provider.conf. This allows users to run commands from the repository root without needing to change directories or create additional config files. * Remove k flag from allow/deny network traffic * Fix getting-started guide and network traffic plugin wrappers - Update getting-started.md to use full paths for YAML files from repo root - Fix kubeconfig references to use kubeplus-saas-provider.json (actual file created) - Add CRD wait step before creating HelloWorldService instances - Fix kubectl-allow-network-traffic and kubectl-deny-network-traffic wrappers to properly handle -k flag by reordering arguments for argparse compatibility - Add -k flag back to allow/deny commands in getting-started guide This allows users to run all commands from the repository root without needing to change directories, and ensures the -k flag works correctly as documented in kubectl-kubeplus-commands help text.
1 parent f763814 commit 78f205d

File tree

3 files changed

+67
-26
lines changed

3 files changed

+67
-26
lines changed

examples/getting-started.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,20 @@ eval $(minikube docker-env)
131131
#### Create HelloWorldService Instances
132132

133133
```sh
134-
kubectl create -f hello-world-service-composition.yaml --kubeconfig=provider.conf
135-
kubectl create -f hs1.yaml --kubeconfig=provider.conf
136-
kubectl create -f hs2.yaml --kubeconfig=provider.conf
134+
kubectl create -f examples/multitenancy/hello-world/hello-world-service-composition.yaml --kubeconfig=kubeplus-saas-provider.json
135+
```
136+
137+
Wait for the HelloWorldService CRD to be registered:
138+
139+
```sh
140+
until kubectl get crds --kubeconfig=kubeplus-saas-provider.json | grep helloworldservices.platformapi.kubeplus ; do echo "Waiting for HelloWorldService CRD to be registered.."; sleep 1; done
141+
```
142+
143+
Then create the HelloWorldService instances:
144+
145+
```sh
146+
kubectl create -f examples/multitenancy/hello-world/hs1.yaml --kubeconfig=kubeplus-saas-provider.json
147+
kubectl create -f examples/multitenancy/hello-world/hs2.yaml --kubeconfig=kubeplus-saas-provider.json
137148
```
138149

139150
#### Test Network Isolation
@@ -142,17 +153,17 @@ kubectl create -f hs2.yaml --kubeconfig=provider.conf
142153

143154
```sh
144155
# Get the Pod name for hs1
145-
HELLOWORLD_POD_HS1=$(kubectl get pods -n hs1 --kubeconfig=provider.conf -o jsonpath='{.items[0].metadata.name}')
156+
HELLOWORLD_POD_HS1=$(kubectl get pods -n hs1 --kubeconfig=kubeplus-saas-provider.json -o jsonpath='{.items[0].metadata.name}')
146157

147158
# Get the Pod IP for hs2
148-
HS2_POD_IP=$(kubectl get pods -n hs2 --kubeconfig=provider.conf -o jsonpath='{.items[0].status.podIP}')
159+
HS2_POD_IP=$(kubectl get pods -n hs2 --kubeconfig=kubeplus-saas-provider.json -o jsonpath='{.items[0].status.podIP}')
149160

150161
# Update and install curl on hs1 pod
151-
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=provider.conf -- apt update
152-
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=provider.conf -- apt install curl -y
162+
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=kubeplus-saas-provider.json -- apt update
163+
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=kubeplus-saas-provider.json -- apt install curl -y
153164

154165
# Test connectivity from hs1 to hs2 using the IP
155-
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=provider.conf -- curl $HS2_POD_IP:5000
166+
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=kubeplus-saas-provider.json -- curl $HS2_POD_IP:5000
156167
```
157168

158169
The connection should be denied.
@@ -161,17 +172,17 @@ kubectl create -f hs2.yaml --kubeconfig=provider.conf
161172

162173
```sh
163174
# Get the Pod name for hs2
164-
HELLOWORLD_POD_HS2=$(kubectl get pods -n hs2 --kubeconfig=provider.conf -o jsonpath='{.items[0].metadata.name}')
175+
HELLOWORLD_POD_HS2=$(kubectl get pods -n hs2 --kubeconfig=kubeplus-saas-provider.json -o jsonpath='{.items[0].metadata.name}')
165176

166177
# Get the Pod IP for hs1
167-
HS1_POD_IP=$(kubectl get pods -n hs1 --kubeconfig=provider.conf -o jsonpath='{.items[0].status.podIP}')
178+
HS1_POD_IP=$(kubectl get pods -n hs1 --kubeconfig=kubeplus-saas-provider.json -o jsonpath='{.items[0].status.podIP}')
168179

169180
# Update and install curl on hs2 pod
170-
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=provider.conf -- apt update
171-
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=provider.conf -- apt install curl -y
181+
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=kubeplus-saas-provider.json -- apt update
182+
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=kubeplus-saas-provider.json -- apt install curl -y
172183

173184
# Test connectivity from hs2 to hs1 using the IP
174-
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=provider.conf -- curl $HS1_POD_IP:5000
185+
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=kubeplus-saas-provider.json -- curl $HS1_POD_IP:5000
175186
```
176187

177188
The connection should be denied.
@@ -181,15 +192,15 @@ kubectl create -f hs2.yaml --kubeconfig=provider.conf
181192
In some scenarios, you might want to enable controlled communication between instances running in different namespaces. KubePlus provides a custom kubectl plugin for this purpose. To allow bi-directional traffic between the two HelloWorldService instances (deployed in namespaces `hs1` and `hs2`), run:
182193

183194
```sh
184-
kubectl allow network traffic hs1 hs2 -k provider.conf
195+
kubectl allow network traffic hs1 hs2 -k kubeplus-saas-provider.json
185196
```
186197

187198
```sh
188199
# Test connectivity from hs1 to hs2 using the IP
189-
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=provider.conf -- curl $HS2_POD_IP:5000
200+
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=kubeplus-saas-provider.json -- curl $HS2_POD_IP:5000
190201

191202
# Test connectivity from hs2 to hs1 using the IP
192-
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=provider.conf -- curl $HS1_POD_IP:5000
203+
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=kubeplus-saas-provider.json -- curl $HS1_POD_IP:5000
193204

194205
kubectl get networkpolicy -o yaml restrict-cross-ns-traffic -n hs1
195206
kubectl get networkpolicy -o yaml restrict-cross-ns-traffic -n hs2
@@ -205,25 +216,25 @@ The connection should be allowed
205216
To deny the traffic between namespace
206217

207218
```sh
208-
kubectl deny network traffic hs1 hs2 -k provider.conf
219+
kubectl deny network traffic hs1 hs2 -k kubeplus-saas-provider.json
209220
```
210221

211222
```sh
212223
# Test connectivity from hs1 to hs2 using the IP
213-
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=provider.conf -- curl $HS2_POD_IP:5000
224+
kubectl exec -it $HELLOWORLD_POD_HS1 -n hs1 --kubeconfig=kubeplus-saas-provider.json -- curl $HS2_POD_IP:5000
214225

215226
# Test connectivity from hs2 to hs1 using the IP
216-
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=provider.conf -- curl $HS1_POD_IP:5000
227+
kubectl exec -it $HELLOWORLD_POD_HS2 -n hs2 --kubeconfig=kubeplus-saas-provider.json -- curl $HS1_POD_IP:5000
217228
```
218229

219230

220231

221232
## Clean Up
222233

223234
```sh
224-
kubectl delete -f hs1-no-replicas.yaml --kubeconfig=provider.conf
225-
kubectl delete -f hs2-no-replicas.yaml --kubeconfig=provider.conf
226-
kubectl delete -f hello-world-service-composition.yaml --kubeconfig=provider.conf
235+
kubectl delete -f examples/multitenancy/hello-world/hs1-no-replicas.yaml --kubeconfig=kubeplus-saas-provider.json
236+
kubectl delete -f examples/multitenancy/hello-world/hs2-no-replicas.yaml --kubeconfig=kubeplus-saas-provider.json
237+
kubectl delete -f examples/multitenancy/hello-world/hello-world-service-composition.yaml --kubeconfig=kubeplus-saas-provider.json
227238
```
228239

229240
Ensure the `helloworldservices.platformapi.kubeplus` CRD is removed.

plugins/kubectl-allow-network-traffic

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,20 @@
22

33
source utils.sh # if you have common utility functions; else remove this line
44

5-
# This wrapper passes all arguments to our Python script.
6-
python3 "$KUBEPLUS_HOME/plugins/network_traffic.py" allow "$@"
5+
# Usage (as advertised in kubectl-kubeplus-commands):
6+
# kubectl allow network traffic <ns1> <ns2> [-k <kubeconfig>]
7+
#
8+
# kubectl will translate that to the plugin name:
9+
# kubectl-allow-network-traffic <ns1> <ns2> [-k <kubeconfig>]
10+
#
11+
# Here we:
12+
# - Take the first two positional args as namespaces
13+
# - Pass any remaining args (e.g. -k <kubeconfig>) as global options
14+
# - Reorder so global options come before the subcommand for argparse
15+
16+
ns1="$1"
17+
ns2="$2"
18+
shift 2
19+
20+
# "$@" now contains any remaining flags (e.g. -k kubeplus-saas-provider.json)
21+
python3 "$KUBEPLUS_HOME/plugins/network_traffic.py" "$@" allow "$ns1" "$ns2"

plugins/kubectl-deny-network-traffic

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,20 @@
22

33
source utils.sh # if you have common utility functions; else remove this line
44

5-
# This wrapper passes all arguments to our Python script.
6-
python3 "$KUBEPLUS_HOME/plugins/network_traffic.py" deny "$@"
5+
# Usage (as advertised in kubectl-kubeplus-commands):
6+
# kubectl deny network traffic <ns1> <ns2> [-k <kubeconfig>]
7+
#
8+
# kubectl will translate that to the plugin name:
9+
# kubectl-deny-network-traffic <ns1> <ns2> [-k <kubeconfig>]
10+
#
11+
# Here we:
12+
# - Take the first two positional args as namespaces
13+
# - Pass any remaining args (e.g. -k <kubeconfig>) as global options
14+
# - Reorder so global options come before the subcommand for argparse
15+
16+
ns1="$1"
17+
ns2="$2"
18+
shift 2
19+
20+
# "$@" now contains any remaining flags (e.g. -k kubeplus-saas-provider.json)
21+
python3 "$KUBEPLUS_HOME/plugins/network_traffic.py" "$@" deny "$ns1" "$ns2"

0 commit comments

Comments
 (0)