Now we will use a wide variety of tools and methodologies to actually test and secure our application environment:
For this, we are going to use eksctl. EKSCTL is a simple CLI tool for creating clusters on AWS Elastic Kubernetes Service (EKS): eksctl Github repo
eksctl will create two Stacks for us, the first is the EKS Control Plane and the second Stack is for the NodeGroup
touch eks-creation.yaml
code eks-creation.yaml
to open the fileAnd paste the following:
apiVersion: eksctl.io/v1alpha5
availabilityZones:
- us-east-1b
- us-east-1a
cloudWatch:
clusterLogging: {}
iam:
vpcResourceControllerPolicy: true
withOIDC: false
kind: ClusterConfig
kubernetesNetworkConfig:
ipFamily: IPv4
managedNodeGroups:
- amiFamily: AmazonLinux2
desiredCapacity: 2
disableIMDSv1: false
disablePodIMDS: false
iam:
withAddonPolicies:
albIngress: false
appMesh: false
appMeshPreview: false
autoScaler: false
awsLoadBalancerController: false
certManager: false
cloudWatch: false
ebs: false
efs: false
externalDNS: false
fsx: false
imageBuilder: false
xRay: false
instanceSelector: {}
instanceType: t3.medium
labels:
alpha.eksctl.io/cluster-name: EKS-DevSecOps-TrendMicroWorkshop
alpha.eksctl.io/nodegroup-name: AmazonLinux
maxSize: 3
minSize: 2
name: AmazonLinux
privateNetworking: false
releaseVersion: ""
securityGroups:
withLocal: null
withShared: null
ssh:
allow: false
publicKeyPath: ""
tags:
alpha.eksctl.io/nodegroup-name: AmazonLinux
alpha.eksctl.io/nodegroup-type: managed
volumeIOPS: 3000
volumeSize: 80
volumeThroughput: 125
volumeType: gp3
metadata:
name: EKS-DevSecOps-TrendMicroWorkshop
region: us-east-1
version: "1.22"
privateCluster:
enabled: false
skipEndpointCreation: false
vpc:
autoAllocateIPv6: false
cidr: 192.168.0.0/16
clusterEndpoints:
privateAccess: false
publicAccess: true
manageSharedNodeSecurityGroupRules: true
nat:
gateway: Disable
eksctl create cluster --config-file=eks-creation.yaml
To use the Continuous Compliance feature we'll need a network plugin with NetworkPolicy support, in this case we will use the Project Calico.
Amazon EKS doesn't maintain the manifests used in the following procedures. The recommended way to install Calico on Amazon EKS is by using the Calico Operator instead of these manifests. But as this is an ephemeral environment for us to learn we will use these manifests.
To install Calico using manifests:
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml
kubectl create -f - <<EOF
apiVersion: operator.tigera.io/v1
kind: Installation
metadata:
name: default
spec: {}
EOF
View the resources in the calico-system namespace.
kubectl get daemonset calico-node --namespace calico-system
Stack Name: ECRTrendWorkShopDevSevOps
RepositoryName The name of the Private Repository on ECR: trendworkshopdevcecops
Click on Next
touch pygoat-deployment.yaml
code pygoat-deployment.yaml
to open the fileDon't forget to put your image URI on the line with the name image: your_container_image_here
Paste the following:
apiVersion: apps/v1
kind: Deployment
metadata:
name: pygoat-deploy
labels:
app: pygoat
spec:
replicas: 2
selector:
matchLabels:
app: pygoat
template:
metadata:
labels:
app: pygoat
spec:
containers:
- name: pygoat
image: your_container_image_here
ports:
- containerPort: 8000
securityContext:
privileged: true
In this pod definition, the securityContext is set to privileged = true.
kubectl apply -f pygoat-deployment.yaml
kubectl get pods
touch loadbalancer-pygoat.yaml
code loadbalancer-pygoat.yaml
to open the filePaste the following:
apiVersion: v1
kind: Service
metadata:
name: pygoat-loadbalancer
spec:
type: LoadBalancer
selector:
app: pygoat
ports:
- protocol: TCP
port: 8000
targetPort: 8000
kubectl create -f loadbalancer-pygoat.yaml
kubectl get svc
http://###:8000/