DevSecOps - Kubernetes DevOps & Security

DevOps Pipeline

Section 2 Topics

In this section, we’ll walk through the essential steps to provision your infrastructure, install necessary software, and build a simple Jenkins pipeline with four stages. By the end, you’ll have:

StepDescriptionScript Location
1Set up a free Azure accountscripts/create-azure-account.sh
2Create a Linux virtual machinescripts/create-vm.sh
3Deploy a single-node Kubernetes clusterscripts/deploy-k8s-cluster.sh
4Install software for hands-on labsscripts/install-lab-software.sh

Prerequisites

Make sure you have:

The image outlines a DevOps pipeline process, including setting up a VM, installing software, understanding use cases, and implementing a basic DevOps pipeline. It also covers DevSecOps and Kubernetes security topics.

1. Set Up a Free Azure Account

  1. Navigate to the Azure free tier page.
  2. Complete the sign-up form to obtain $200 in credits.
  3. Verify your email and phone number.

Warning

Free credits expire after 30 days. Monitor your usage in the Azure Portal to avoid unexpected charges.

2. Create a Virtual Machine

Use the Azure CLI to spin up a Linux VM:

az login
az group create --name DevOpsRG --location eastus
az vm create \
  --resource-group DevOpsRG \
  --name DevNode \
  --image UbuntuLTS \
  --size Standard_B1s \
  --admin-username azureuser \
  --generate-ssh-keys

3. Deploy a Single-Node Kubernetes Cluster

Install Kubernetes with kubeadm:

ssh azureuser@<VM_PUBLIC_IP>
sudo apt-get update && sudo apt-get install -y docker.io kubeadm
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

4. Install Software for Hands-On Labs

Install common DevOps tools:

# Jenkins
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update && sudo apt-get install -y openjdk-11-jdk jenkins

# Helm, Terraform, Azure CLI extensions
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
sudo apt-get install -y unzip
curl https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip -o tf.zip
unzip tf.zip && sudo mv terraform /usr/local/bin/
az extension add --name aks-preview

5. Create a Basic Jenkins Pipeline

Here’s a simple Jenkinsfile with four stages:

pipeline {
  agent any
  stages {
    stage('Clone Repo') {
      steps { git 'https://github.com/your-org/your-repo.git' }
    }
    stage('Build') {
      steps { sh 'mvn clean package' }
    }
    stage('Test') {
      steps { sh 'mvn test' }
    }
    stage('Deploy') {
      steps { sh './scripts/deploy.sh' }
    }
  }
}

References

Watch Video

Watch video content

Previous
Tools Explored in this course