--- title: "Pipeline Phase - Deploy" chapter: true weight: 50 pre: "5. " --- # Deploy Stage Now we will use a wide variety of tools and methodologies to actually test and secure our application environment: - [Zaproxy](https://github.com/zaproxy/zaproxy) - [Cloud One Network Security](https://cloudone.trendmicro.com/) - [Cloud One Container Security](https://cloudone.trendmicro.com/) #### The application that we will use in our company will be this one: - [Pygoat-TM](https://github.com/JustinDPerkins/pygoat-tm) --- ### Deploy the infrastructure that will host our application on AWS EKS (Elastic Kubernetes Service) **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** {{% notice info %}}

eksctl will create two Stacks for us, the first is the EKS Control Plane and the second Stack is for the NodeGroup

{{% /notice %}} --- ### 1. In the terminal create the configuration file so that we can create our cluster control plane and our node group in EKS using eksctl - In the terminal, type the command ```touch eks-creation.yaml``` - In the left column where it shows the files, double click on the file **eks-creation.yaml** - Or type the command ```code eks-creation.yaml``` to open the file **And 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 - Type the command to create the Cluster and Node Group ```eksctl create cluster --config-file=eks-creation.yaml``` ![EKS](/images/eksctl1.PNG) #### To follow the creation process - You can follow through the terminal ![EKS](/images/eksctl3.PNG) ![EKS](/images/eksctl6.PNG) #### Or you can go to the AWS console, in the CloudFormation service - Follow up the events during the creation of the stack **EKS-DevSecOps-TrendMicroWorkshop** and **eksctl-EKS-DevSecOps-TrendMicroWorkshop-nodegroup-AmazonLinux** - It can take some time - Select the **Events** tab - Click **Refresh** ![EKS](/images/eksctl2.PNG) ![EKS](/images/eksctl4.PNG) --- ### 1.2. Ensure both stacks status has reached Create_Complete. - Select the **Stack info** tab ![EKS](/images/eksctl5.PNG) --- ### One of the technologies that we will use to protect our EKS Cluster is Cloud One Container Security. {{% notice info %}}

To use the Continuous Compliance feature we'll need a network plugin with NetworkPolicy support, in this case we will use the Project Calico.

{{% /notice %}} --- ### 1.1. Now Let's follow the instructions to [install Calico add-on on our EKS cluster](https://docs.aws.amazon.com/eks/latest/userguide/calico.html) {{% notice warning %}}

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.

{{% /notice %}} **To install Calico using manifests:** kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml kubectl create -f - < Don't forget to put your image URI on the line with the name image: your_container_image_here

{{% /notice %}} **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 {{% notice info %}}

In this pod definition, the securityContext is set to privileged = true.

{{% /notice %}} ![Pygoat-Application](/images/app2.PNG) --- ### 2.2. Go to your repository in AWS ECR - Copy the **Image URI** ![Pygoat-Application](/images/app3.PNG) - And replace **your_container_image_here** which is in your **pygoat-deployment.yaml** file ![Pygoat-Application](/images/app5.PNG) - **Save the file** --- ### 2.2. Let's deploy our Pygoat application to EKS - Type the command ```kubectl apply -f pygoat-deployment.yaml``` ![Pygoat-Application](/images/app4.PNG) --- ### 2.3. Confirm that the pods are already running - Type the command ```kubectl get pods``` - Wait until **running** is showing ![Pygoat-Application](/images/app6.PNG) ![Pygoat-Application](/images/app7.PNG) ---- ### 2.4. Let's create a LoadBalancer service to access our application externally - Type the command ```touch loadbalancer-pygoat.yaml``` - In the left column where it shows the files, double click on the file **loadbalancer-pygoat.yaml** - Or type the command ```code loadbalancer-pygoat.yaml``` to open the file ![Pygoat-Application](/images/app8.PNG) ![Pygoat-Application](/images/app9.PNG) --- ### 2.5. In the loadbalancer-pygoat file **Paste the following:** apiVersion: v1 kind: Service metadata: name: pygoat-loadbalancer spec: type: LoadBalancer selector: app: pygoat ports: - protocol: TCP port: 8000 targetPort: 8000 ![Pygoat-Application](/images/app13.PNG) - **Save the file** --- ### 2.6. To create the LoadBalancer - Type the command ```kubectl create -f loadbalancer-pygoat.yaml``` ![Pygoat-Application](/images/app10.PNG) --- ### 2.7. Confirm that LoadBalancer is already exposed - Type the command ```kubectl get svc``` - Copy the value that appears in **EXTERNAL-IP** ![Pygoat-Application](/images/app11.PNG) --- ### 2.8. Access the application - In your browser paste the URL ```http://###:8000/``` - **Replace the ### with the value you got from your EXTERNAL-IP** - It may take up to 2 to 3 minutes to access the application ![Pygoat-Application](/images/app12.PNG) -------- ### Perfect! We now have our infrastructure ready so we can use our security processes! :star-struck: :robot: :white_check_mark: :cloud: