Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubleshooting module pod #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions manifests/modules/troubleshooting/pod/crash/.workshop/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if kubectl get deployment efs-app -n default > /dev/null 2>&1; then
kubectl delete deployment efs-app -n default
else
echo "Deployment efs-app does not exist."
fi

if kubectl get pvc efs-claim -n default > /dev/null 2>&1; then
kubectl delete pvc efs-claim -n default
else
echo "PVC efs-claim does not exist."
fi
PV_NAME=$(kubectl get pv -o jsonpath='{.items[?(@.spec.claimRef.name=="efs-claim")].metadata.name}')
if [ -n "$PV_NAME" ]; then
kubectl delete pv "$PV_NAME"
else
echo "No PV associated with efs-claim."
fi

if kubectl get storageclass efs-sc > /dev/null 2>&1; then
kubectl delete storageclass efs-sc
else
echo "Storage class efs-sc does not exist."
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: efs-sc
provisioner: efs.csi.aws.com
parameters:
provisioningMode: efs-ap
fileSystemId: ${filesystemid}
directoryPerms: "700"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: efs-claim
spec:
accessModes:
- ReadWriteMany
storageClassName: efs-sc
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: efs-app
labels:
app: efs-app
spec:
replicas: 1
selector:
matchLabels:
app: efs-app
template:
metadata:
labels:
app: efs-app
spec:
containers:
- name: app
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /example/out.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /example
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: efs-claim
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
terraform {
required_providers {
# kubectl = {
# source = "gavinbunney/kubectl"
# version = ">= 1.14"
# }
}
}

provider "aws" {
region = "us-east-1"
alias = "virginia"
}

data "aws_caller_identity" "current" {}

locals {
account_id = data.aws_caller_identity.current.account_id
}

data "aws_vpc" "selected" {
tags = {
created-by = "eks-workshop-v2"
env = var.addon_context.eks_cluster_id
}
}

data "aws_subnets" "public" {
tags = {
created-by = "eks-workshop-v2"
env = var.addon_context.eks_cluster_id
}

filter {
name = "tag:Name"
values = ["*Public*"]
}
}

/*
data "aws_eks_cluster" "cluster" {
name = var.eks_cluster_id
}
*/

module "eks_blueprints_addons" {
source = "aws-ia/eks-blueprints-addons/aws"
version = "1.16.2"

enable_aws_efs_csi_driver = true
aws_efs_csi_driver = {
wait = true
}

cluster_name = var.addon_context.eks_cluster_id
cluster_endpoint = var.addon_context.aws_eks_cluster_endpoint
cluster_version = var.eks_cluster_version
oidc_provider_arn = var.addon_context.eks_oidc_provider_arn
}


resource "aws_efs_file_system" "efs" {
tags = {
Name = "eks-workshop-efs"
}
}

resource "aws_efs_mount_target" "mount_targets" {
for_each = toset(data.aws_subnets.public.ids)
file_system_id = resource.aws_efs_file_system.efs.id
subnet_id = each.value
security_groups = [resource.aws_security_group.efs_sg.id]
}

resource "aws_security_group" "efs_sg" {
name = "efs_sg"
description = "Allow tarffic to efs"
vpc_id = data.aws_vpc.selected.id

tags = {
Name = "efs_sg"
}
}

resource "aws_vpc_security_group_ingress_rule" "allow_ipv4" {
security_group_id = aws_security_group.efs_sg.id
cidr_ipv4 = data.aws_vpc.selected.cidr_block
from_port = 80
ip_protocol = "tcp"
to_port = 80
}


resource "aws_vpc_security_group_egress_rule" "allow_all_traffic_ipv4" {
security_group_id = aws_security_group.efs_sg.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "-1" # semantically equivalent to all ports
}

data "template_file" "deployment_yaml" {
template = file("/home/ec2-user/environment/eks-workshop/modules/troubleshooting/pod/crash/.workshop/terraform/deployment.yaml.tpl")

vars = {
filesystemid = resource.aws_efs_file_system.efs.id
}
}

resource "local_file" "deployment_yaml" {
filename = "/home/ec2-user/environment/eks-workshop/modules/troubleshooting/pod/crash/deployment.yaml"
content = data.template_file.deployment_yaml.rendered
}

resource "null_resource" "kustomize_app" {
triggers = {
always_run = timestamp()
}

provisioner "local-exec" {
command = "kubectl apply -f ~/environment/eks-workshop/modules/troubleshooting/pod/crash/"
when = create
}

depends_on = [resource.local_file.deployment_yaml, resource.aws_efs_file_system.efs]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "account_id" {
value = local.account_id
description = "account id env variable"
}

output "environment_variables" {
description = "Environment variables to be added to the IDE shell"
value = merge({
VPC_ID = data.aws_vpc.selected.id
}, {
for index, id in data.aws_subnets.public.ids : "PUBLIC_SUBNET_${index + 1}" => id
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# tflint-ignore: terraform_unused_declarations
variable "eks_cluster_id" {
description = "EKS cluster name"
type = string
default = "eks-workshop"
}

# tflint-ignore: terraform_unused_declarations
variable "eks_cluster_version" {
description = "EKS cluster version"
type = string
}

# tflint-ignore: terraform_unused_declarations
variable "cluster_security_group_id" {
description = "EKS cluster security group ID"
type = any
}

# tflint-ignore: terraform_unused_declarations
variable "addon_context" {
description = "Addon context that can be passed directly to blueprints addon modules"
type = any
}

# tflint-ignore: terraform_unused_declarations
variable "tags" {
description = "Tags to apply to AWS resources"
type = any
}

# tflint-ignore: terraform_unused_declarations
variable "resources_precreated" {
description = "Have expensive resources been created already"
type = bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if kubectl get deployment ui-new -n default > /dev/null 2>&1; then
kubectl delete deploy ui-new -n default
else
echo "delpoyment ui-new does not exist"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
terraform {
required_providers {
# kubectl = {
# source = "gavinbunney/kubectl"
# version = ">= 1.14"
# }
}
}

provider "aws" {
region = "us-east-1"
alias = "virginia"
}

data "aws_caller_identity" "current" {}

locals {
account_id = data.aws_caller_identity.current.account_id
}


resource "null_resource" "kustomize_app" {
triggers = {
always_run = timestamp()
}

provisioner "local-exec" {
command = "kubectl apply -f ~/environment/eks-workshop/modules/troubleshooting/pod/image/"
when = create
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "account_id" {
value = local.account_id
description = "account id env variable"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# tflint-ignore: terraform_unused_declarations
variable "eks_cluster_id" {
description = "EKS cluster name"
type = string
default = "eks-workshop"
}

# tflint-ignore: terraform_unused_declarations
variable "eks_cluster_version" {
description = "EKS cluster version"
type = string
}

# tflint-ignore: terraform_unused_declarations
variable "cluster_security_group_id" {
description = "EKS cluster security group ID"
type = any
}

# tflint-ignore: terraform_unused_declarations
variable "addon_context" {
description = "Addon context that can be passed directly to blueprints addon modules"
type = any
}

# tflint-ignore: terraform_unused_declarations
variable "tags" {
description = "Tags to apply to AWS resources"
type = any
}

# tflint-ignore: terraform_unused_declarations
variable "resources_precreated" {
description = "Have expensive resources been created already"
type = bool
}
Loading