Skip to content

Commit 2746357

Browse files
author
Lukonde Mwila
committed
udpated the eks container network o11y docs with code snippers for bash and updated tf code snippet
1 parent e22f3b4 commit 2746357

File tree

1 file changed

+81
-6
lines changed

1 file changed

+81
-6
lines changed

latest/ug/observability/container-network-observability.adoc

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,78 @@ The following permissions are required to enable the feature and visualize the s
9090
}
9191
----
9292

93+
== Using {aws} CLI, EKS API and NFM API
94+
95+
[source,bash]
96+
----
97+
#!/bin/bash
98+
99+
# Script to create required Network Flow Monitor resources
100+
set -e
101+
102+
CLUSTER_NAME="my-eks-cluster"
103+
CLUSTER_ARN="arn:aws:eks:{Region}:{Account}:cluster/{ClusterName}"
104+
REGION="us-west-2"
105+
AGENT_NAMESPACE="amazon-network-flow-monitor"
106+
107+
echo "Creating Network Flow Monitor resources..."
108+
109+
# Check if Network Flow Monitor agent is running in the cluster
110+
echo "Checking for Network Flow Monitor agent in cluster..."
111+
if kubectl get pods -n "$AGENT_NAMESPACE" --no-headers 2>/dev/null | grep -q "Running"; then
112+
echo "Network Flow Monitor agent exists and is running in the cluster"
113+
else
114+
echo "Network Flow Monitor agent not found. Installing as EKS addon..."
115+
aws eks create-addon \
116+
--cluster-name "$CLUSTER_NAME" \
117+
--addon-name "$AGENT_NAMESPACE" \
118+
--region "$REGION"
119+
echo "Network Flow Monitor addon installation initiated"
120+
fi
121+
122+
# Get Account ID
123+
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
124+
125+
echo "Cluster ARN: $CLUSTER_ARN"
126+
echo "Account ID: $ACCOUNT_ID"
127+
128+
# Check for existing scope
129+
echo "Checking for existing Network Flow Monitor Scope..."
130+
EXISTING_SCOPE=$(aws networkflowmonitor list-scopes --region $REGION --query 'scopes[0].scopeArn' --output text 2>/dev/null || echo "None")
131+
132+
if [ "$EXISTING_SCOPE" != "None" ] && [ "$EXISTING_SCOPE" != "null" ]; then
133+
echo "Using existing scope: $EXISTING_SCOPE"
134+
SCOPE_ARN=$EXISTING_SCOPE
135+
else
136+
echo "Creating new Network Flow Monitor Scope..."
137+
SCOPE_RESPONSE=$(aws networkflowmonitor create-scope \
138+
--targets "[{\"targetIdentifier\":{\"targetId\":{\"accountId\":\"${ACCOUNT_ID}\"},\"targetType\":\"ACCOUNT\"},\"region\":\"${REGION}\"}]" \
139+
--region $REGION \
140+
--output json)
141+
142+
SCOPE_ARN=$(echo $SCOPE_RESPONSE | jq -r '.scopeArn')
143+
echo "Scope created: $SCOPE_ARN"
144+
fi
145+
146+
# Create Network Flow Monitor with EKS Cluster as local resource
147+
echo "Creating Network Flow Monitor..."
148+
MONITOR_RESPONSE=$(aws networkflowmonitor create-monitor \
149+
--monitor-name "${CLUSTER_NAME}-monitor" \
150+
--local-resources "type=AWS::EKS::Cluster,identifier=${CLUSTER_ARN}" \
151+
--scope-arn "$SCOPE_ARN" \
152+
--region $REGION \
153+
--output json)
154+
155+
MONITOR_ARN=$(echo $MONITOR_RESPONSE | jq -r '.monitorArn')
156+
157+
echo "Monitor created: $MONITOR_ARN"
158+
159+
echo "Network Flow Monitor setup complete!"
160+
echo "Monitor ARN: $MONITOR_ARN"
161+
echo "Scope ARN: $SCOPE_ARN"
162+
echo "Local Resource: AWS::EKS::Cluster (${CLUSTER_ARN})"
163+
----
164+
93165
== Using Infrastructure as Code (IaC)
94166

95167
=== Terraform
@@ -98,7 +170,8 @@ If you are using Terraform to manage your {aws} cloud infrastructure, you can in
98170

99171
===== NFM Scope
100172

101-
```
173+
[source,terraform]
174+
----
102175
data "aws_caller_identity" "current" {}
103176
104177
resource "aws_networkflowmonitor_scope" "example" {
@@ -116,11 +189,12 @@ resource "aws_networkflowmonitor_scope" "example" {
116189
Name = "example"
117190
}
118191
}
119-
```
192+
----
120193

121194
===== NFM Monitor
122195

123-
```
196+
[source,terraform]
197+
----
124198
resource "aws_networkflowmonitor_monitor" "example" {
125199
monitor_name = "eks-cluster-name-monitor"
126200
scope_arn = aws_networkflowmonitor_scope.example.scope_arn
@@ -139,16 +213,17 @@ resource "aws_networkflowmonitor_monitor" "example" {
139213
Name = "example"
140214
}
141215
}
142-
```
216+
----
143217

144218
===== EKS add-on for NFM
145219

146-
```
220+
[source,terraform]
221+
----
147222
resource "aws_eks_addon" "example" {
148223
cluster_name = aws_eks_cluster.example.name
149224
addon_name = "aws-network-flow-monitoring-agent"
150225
}
151-
```
226+
----
152227

153228
== How does it work?
154229

0 commit comments

Comments
 (0)