Deepak Ingale 1
ServiceNow Employee

Disclaimer: The views in this post are my own and do not represent ServiceNow, Inc. The setup was built and tested in a personal lab using non-production resources and is shared for reference only. Actual implementation should align with your organization's enterprise standards, including security policies, best practices, and change processes. Your environment and ServiceNow release may differ, so check the official documentation before applying anything. Shared as-is, without warranty.

 

In this article, we are going to cover how to create Kubernetes Cluster, Node groups in AWS and trigger Kubernetes Discovery from ServiceNow. Discover an Amazon EKS cluster in a member account from a MID Server in a separate accessor account, using IAM roles only. No access keys, no Kubernetes service account token

 

AWS and Kubernetes run two separate authorization systems, and EKS joins them at exactly one point.

IAM decides who you are when you call AWS. Kubernetes RBAC decides what you may read inside the

cluster.

 

Step 1 [ServiceNow]: Set the system properties

 

What each property does

 

sn_itom_pattern.k8s_aws_cli_to_generate_token chooses between two ways of getting the

bearer token the cluster expects. Set to true, the MID Server shells out to the AWS CLI and runs aws eks

get-token, which means the CLI must be installed on the MID host and configured with working

credentials.

Set to false, the pattern generates the token itself through the STS AssumeRole flow, using

the role the cloud service account already uses.

 

For a credential-less setup, false is the right choice. It needs no CLI on the MID host, no stored

credentials, and it reuses the same assume-role path already proven by the rest of your cloud discovery.

 

sn_itom_pattern.k8s_create_schedule_enabled controls whether cloud discovery, on finding a

cluster, automatically creates a Kubernetes discovery schedule for it. Its default is false, which is why a

cluster can appear in the CMDB with nothing inside it. Set to true, you get the second discovery stage

 

sn_itom_pattern.k8s_midserver names the MID Server that the generated schedule will use. The

schedule needs a MID Server that can reach the cluster endpoint

 

 

DeepakIngale1_0-1795974116304.png

 

 

Step 2 [AWS]: Assign Elastic IP Address to MID Server

 

An EC2 instance's auto-assigned public IP is released when the instance stops and a new one is allocated

when it starts. Since you will almost certainly stop this instance between sessions to save cost, the allowlist

would break on your next restart, and the symptom appears days later with no obvious connection to the

cause.

An Elastic IP is retained across stop and start, which removes that failure entirely.

  • Go to EC2 > Elastic IPs > Allocate Elastic IP address.
  • Select the new address, choose Actions > Associate Elastic IP address, and pick the MID Server

instance.

  • Confirm the Associated instance column now shows that instance.

 

Step 2 [AWS: Member account]: Create Cluster and Node Group

 

For a credential-less setup, false is the right choice. It needs no CLI on the MID host, no stored

credentials, and it reuses the same assume-role path already proven by the rest of your cloud discovery.

 

Go to EKS > Add cluster > Create, in the same region as the MID Server.

Configuration

  • Custom configuration, with EKS Auto Mode off.
  • Name: sn-demo-01
  • Kubernetes version: the newest offered.
  • Cluster IAM role: create the recommended role.

 

Authentication mode:  

Choose EKS API and ConfigMap.

 

  • Endpoint access: Public and private.
  • Public access CIDR: the MID Server's Elastic IP, with /32. The cluster takes 10 to 15 minutes to become Active.

 

DeepakIngale1_1-1795974116312.png

 

 

 

 

 

 

DeepakIngale1_2-1795974116314.png

 

DeepakIngale1_3-1795974116316.png

 

Step 3 [AWS : Member account]: Create the node group

 

Go to EKS > Clusters > sn-discovery-test > Compute > Add node group.

  • Name: sn-demo-01-ng
  • Node IAM role: AWSEKSNodeRole
  • Instance type: t3.small
  • AMI type: Amazon Linux 2023, x86_64
  • Disk: 20 GiB
  • Scaling: minimum 1, maximum 1, desired 1

One node is enough. Discovery reads the cluster's inventory. Creation normally takes 5 to 10 mins.

 

DeepakIngale1_4-1795974116318.png

 

 

Step 4 [member account]: Create Access entry in Cluster for IAM Role

 

Go to EKS > Clusters > sn-demo-01 > Access > Create access entry.

  • IAM principal:

arn:aws:iam::<MEMBER-ACCOUNT-ID>:role/SnowAwsCloudDiscoveryPatternsRole

  • Type: Standard.
  • Add the access policy AmazonEKSViewPolicy scoped to Cluster.

 

Step 5  [AWS: Accessor account]: via EC2 mid server

 

Every EKS API server presents a TLS certificate issued by a private certificate authority unique to that

cluster. It is not signed by any public CA, so nothing trusts it by default. Check the certificate associated with cluster and then import in key store

 

aws eks describe-cluster --name sn-demo-01 \

--region us-east-1 --profile member1 \

--query 'cluster.certificateAuthority.data' \

--output text | base64 -d > /tmp/eks-ca.crt

openssl x509 -in /tmp/eks-ca.crt -noout -subject -dates

 

 

import it into the MID Server trust store. The trust store is a Java keystore inside the MID Server's bundled runtime.

 

KT=/opt/servicenow/mid/agent/jre/bin/keytool

KS=/opt/servicenow/mid/agent/jre/lib/security/cacerts

$KT -import -alias eks-sn-demo-01 -file /tmp/eks-ca.crt \

-keystore $KS -storepass <<Store Password>>

 

Enter “yes” and go ahead. Once certificate is imported, restart the mid server service.

 

 

Step 6 [AWS: Member account]: Create the nodes ClusterRole and binding via cloudshell

 

Open Cloud Shell in the member account and run below

 

cat > snow-discovery-rbac.yaml <<'EOF'
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: snow-discovery-nodes-read
rules:
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: snow-discovery-nodes-read
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: snow-discovery-nodes-read
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: snow-discovery-read
EOF

aws eks update-kubeconfig --name sn-demo-01 --region us-east-1
kubectl apply -f snow-discovery-rbac.yaml

 

Step 6 [AWS: Member account]: Bind the group to the discovery role's access entry via cloudshell

 

aws eks update-access-entry --cluster-name sn-demo-01 \
  --principal-arn arn:aws:iam::561297299025:role/SnowAwsCloudDiscoveryPatternsRole \
  --kubernetes-groups snow-discovery-read --region us-east-1

 

Step 7 [AWS: Member account]: Verify the discovery role's policies via cloudshell

 

aws eks list-associated-access-policies --cluster-name sn-demo-01 \
  --principal-arn arn:aws:iam::561297299025:role/SnowAwsCloudDiscoveryPatternsRole --region us-east-1

 

Step 8 [AWS: Accessor account]: Test on the MID server

 

mkdir -p ~/.aws

cat > ~/.aws/config << 'EOF'

[profile member1]

role_arn = arn:aws:iam::561297299025:role/SnowAwsCloudDiscoveryPatternsRole

credential_source = Ec2InstanceMetadata

region = us-east-1

EOF

 

aws eks update-kubeconfig --name sn-demo-01 --region us-east-1 --profile member1

 

Wait about a minute, then run

 

kubectl config current-context
kubectl get nodes
kubectl auth can-i list nodes

 

once you see nodes are listed down and in READY state, which means that connectivity from mid server in accessor account to cluster in member account is well established.

 

Step 9 [ServiceNow]: Run cloud discovery schedule for member account where cluster is present.

 

DeepakIngale1_5-1795974116325.png

 

 

 

 

DeepakIngale1_6-1795974116333.png

 

 

 

You would notice that Kubernetes Discovery Shedule is auto created, schedule record syntax is k8s_accountNumber_clusterName

DeepakIngale1_7-1795974116338.png

 

 

Once discovery is completed, we can see our Cluster along with Pods, VMs etc.

 

DeepakIngale1_8-1795974116343.png

 

Version history
Last update:
20m ago
Updated by:
Contributors