Skip to content

Commit

Permalink
Update README and add scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
niloysh committed Oct 14, 2023
1 parent 6b3ddaa commit 5159bc4
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Open5GS
# open5gs-k8s

This repository contains the necessary files and resources to deploy and operate Open5GS, an open-source 5G core network implementation. It provides Kubernetes manifest files for deploying Open5GS using microservices, an all-in-one deployment variant, and Open5GS WebUI. Additionally, there are manifest files for deploying the MongoDB database and network attachment definitions for Open5GS.

Expand All @@ -12,28 +12,35 @@ The repository is organized as follows:
- `open5gs-aio/`: Contains Kubernetes manifest files for deploying Open5GS as an all-in-one deployment variant.
- `open5gs-webui/`: Contains Kubernetes manifest files for deploying the Open5GS WebUI.
- `mongodb/`: Contains Kubernetes manifest files for deploying the MongoDB database, which is a prerequisite for deploying Open5GS.
- `mongo-tools`: Contains scripts for adding and listing subscribers to Open5GS mongodb database using python. Also contains sample subscriber information.
- `networks5g/`: Contains network attachment definitions for Open5GS. Two variants are provided: one using Macvlan and the other using Open vSwitch (OVS).
- `ueransim/`: Contains Kubernetes files for running UERANSIM-based simulated gNB and UEs.

## Deployment

To deploy Open5GS and its components, follow the deployment steps below:

0. Set up OVS bridges. On each K8s cluster node, add the OVS bridges: n2br, n3br, and n4br. Connect nodes using these bridges and OVS-based VXLAN tunnels.
1. Deploy the MongoDB database using the Kubernetes manifest files provided in the `mongodb/` directory.
2. Deploy the network attachment definitions using the appropriate variant from the `networks5g/` directory (either Macvlan or OVS).
3. Choose one of the following deployment options:
- For a microservices-based deployment, use the Kubernetes manifest files in the `open5gs/` directory.
- For an all-in-one deployment variant, use the Kubernetes manifest files in the `open5gs-aio/` directory.
- To deploy the Open5GS WebUI, use the Kubernetes manifest files in the `open5gs-webui/` directory.

Please refer to the specific directories for more detailed instructions and usage examples.

## Documentation
4. The `ueransim` directory contains Kubernetes manifest files for both gNB and UEs. First, deploy UERANSIM gNB and wait for NGAP connection to succeed.
5. Ensure correct UE subscriber information is inserted via the web UI. Subscriber details are found in UE config files.
6. Deploy UERANSIM UEs.

For more detailed information about Open5GS and its usage, please consult the official Open5GS documentation. You can find additional resources, tutorials, and community support on the Open5GS website.
Please refer to the specific directories for more detailed instructions and usage examples.

## Contributing
## Scripts
The `bin` directory contains scripts for easily viewing logs and getting a shell on any of the NFs. Usage is as follows.
```bash
./k8s-log.sh <nf> <namespace>
./k8s-log.sh amf open5gs
```

Contributions to this repository are welcome! If you have any improvements, bug fixes, or new features to contribute, please follow the guidelines outlined in the CONTRIBUTING.md file.

## License

Expand Down
42 changes: 42 additions & 0 deletions bin/k8s-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

if [[ $# -eq 0 ]]; then
echo "Usage: k8s-logs <keyword> [namespace]"
exit 1
fi

keyword=$1
namespace=$2

if [[ -z $namespace ]]; then
echo "Select namespace:"
namespaces=($(kubectl get namespaces -o name | cut -d/ -f2))
PS3="Namespace: "
select namespace in "${namespaces[@]}"; do
if [[ -n $namespace ]]; then
break
fi
done
fi

pod=$(kubectl get pods -n "$namespace" | grep "$keyword" | head -1 | awk '{print $1}')
if [[ -z $pod ]]; then
echo "No pods found for keyword: $keyword"
exit 1
fi

containers=($(kubectl get pods "$pod" -n "$namespace" -o jsonpath='{.spec.containers[*].name}'))
if [[ ${#containers[@]} -eq 1 ]]; then
container=${containers[0]}
else
echo "Select container:"
PS3="Container: "
select container in "${containers[@]}"; do
if [[ -n $container ]]; then
break
fi
done
fi

kubectl logs -f "$pod" -n "$namespace" -c "$container"

82 changes: 82 additions & 0 deletions bin/k8s-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

# function to print usage message
function usage {
echo "Usage: $0 keyword [namespace]"
echo " keyword: a string that identifies the pod you want to access, e.g. amf, smf, upf"
echo " namespace (optional): the Kubernetes namespace where the pod is running"
echo "If no namespace is specified, a namespace picker will be displayed."
}

# Function to prompt the user to select a namespace from a list
select_namespace() {
echo "Select a namespace:"
select NAMESPACE in $(kubectl get namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
do
if [ -n "$NAMESPACE" ]
then
break
fi
done
}

# Function to prompt the user to select a container from a list
select_container() {
echo "Select a container:"
select CONTAINER in $(kubectl get pod $POD -n $NAMESPACE -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}')
do
if [ -n "$CONTAINER" ]
then
break
fi
done
}

# Display help message if no arguments provided
if [ "$#" -eq 0 ]
then
usage
exit 1
fi

POD_KEYWORD=$1

# Prompt for namespace if not specified
if [ "$#" -eq 1 ]
then
select_namespace
else
NAMESPACE=$2
fi

POD=$(kubectl get pods -n $NAMESPACE | grep "$POD_KEYWORD" | awk '{print $1}')

if [ -z "$POD" ]
then
echo "No pod found with keyword: $POD_KEYWORD in namespace: $NAMESPACE"
exit 1
fi

CONTAINER_COUNT=$(kubectl get pod $POD -n $NAMESPACE -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}' | wc -l)

if [ "$CONTAINER_COUNT" -eq 1 ]
then
CONTAINER=$(kubectl get pod $POD -n $NAMESPACE -o jsonpath='{.spec.containers[0].name}')
else
select_container
fi

# Try bash shell, fallback to sh
SHELLS=("bash" "sh")
for SHELL in "${SHELLS[@]}"
do
if kubectl exec $POD -n $NAMESPACE -c $CONTAINER -- $SHELL -c 'exit 0' > /dev/null 2>&1
then
kubectl exec -it $POD -n $NAMESPACE -c $CONTAINER -- $SHELL
exit 0
fi
done

echo "No supported shell found in pod: $POD"
exit 1

0 comments on commit 5159bc4

Please sign in to comment.