diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml new file mode 100644 index 0000000..cf1ad0c --- /dev/null +++ b/.github/workflows/pipeline.yaml @@ -0,0 +1,50 @@ +name: Infra CI + +on: + push: + paths: + - 'terraform/**' + - 'kubernetes/**' + - '.github/workflows/pipeline.yaml' + pull_request: + paths: + - 'terraform/**' + - 'kubernetes/**' + - '.github/workflows/pipeline.yaml' + +jobs: + terraform: + name: Terraform Checks + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Terraform Init + run: terraform -chdir=terraform init + + - name: Terraform Format + run: terraform -chdir=terraform fmt -check + + - name: Terraform Validate + run: terraform -chdir=terraform validate + + kube-lint: + name: Kubernetes YAML Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install kubeval + run: | + curl -sLO https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-linux-amd64.tar.gz + tar xf kubeval-linux-amd64.tar.gz + sudo mv kubeval /usr/local/bin/ + + - name: Lint Kubernetes YAML + run: | + find kubernetes -name '*.yaml' -print0 | xargs -0 -n1 kubeval diff --git a/kubernetes/cronjob-v2.yaml b/kubernetes/cronjob-v2.yaml index 8381cd4..d463506 100644 --- a/kubernetes/cronjob-v2.yaml +++ b/kubernetes/cronjob-v2.yaml @@ -1,14 +1,19 @@ -apiVersion: batch/v1beta1 +#apiVersion: batch/v1beta1 +apiVersion: batch/v1 kind: CronJob metadata: name: "amazing-cron-job" spec: - schedule: '*/15 9-19 * *' + #schedule: '*/15 9-19 * *' + schedule: '*/15 9-19 * * *' + concurrencyPolicy: Forbid + successfulJobsHistoryLimit: 1 + failedJobsHistoryLimit: 1 jobTemplate: spec: template: spec: restartPolicy: Never - concurrencyPolicy: Forbid - successfulJobHistoryLimit: 1 - failedJobsHistoryLimit: 1 \ No newline at end of file + # concurrencyPolicy: Forbid + # successfulJobHistoryLimit: 1 + # failedJobsHistoryLimit: 1 \ No newline at end of file diff --git a/kubernetes/cronjob.yaml b/kubernetes/cronjob.yaml index 370081e..9a2da58 100644 --- a/kubernetes/cronjob.yaml +++ b/kubernetes/cronjob.yaml @@ -1,8 +1,22 @@ -apiVersion: batch/v1beta1 +#apiVersion: batch/v1beta1 +apiVersion: batch/v1 kind: CronJob metadata: name: amazing-cron-job spec: schedule: '*/1 * * * *' startingDeadlineSeconds: 10 - concurrencyPolicy: Allow \ No newline at end of file + concurrencyPolicy: Allow + jobTemplate: + spec: + template: + spec: + containers: + - name: hello + image: busybox + args: + - /bin/sh + - -c + - echo Hello from the Kubernetes cluster! + restartPolicy: OnFailure + \ No newline at end of file diff --git a/kubernetes/frontend.yaml b/kubernetes/frontend.yaml index 0c078db..ceb1258 100644 --- a/kubernetes/frontend.yaml +++ b/kubernetes/frontend.yaml @@ -5,4 +5,7 @@ metadata: spec: containers: - name: app - image: images.ta.example/app:v4 \ No newline at end of file + image: images.ta.example/app:v4 + ports: + - containerPort: 80 + restartPolicy: Always \ No newline at end of file diff --git a/kubernetes/ingress.yaml b/kubernetes/ingress.yaml index a1e0851..724017d 100644 --- a/kubernetes/ingress.yaml +++ b/kubernetes/ingress.yaml @@ -1,13 +1,20 @@ -apiVersion: v1 +#apiVersion: v1 +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-test spec: rules: - - host: * - http: - paths: - - path: /endpoint - backend: - serviceName: s1 - servicePort: 80 \ No newline at end of file + # - host: * + - http: + paths: + - path: /endpoint + pathType: Prefix + # backend: + # serviceName: s1 + # servicePort: 80 + backend: + service: + name: s1 + port: + number: 80 \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf index c7dc7fe..4c2880b 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -68,7 +68,11 @@ resource "aws_iam_instance_profile" "example_profile" { resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id - instance_type = "t2.macro" + #instance_type = "t2.macro" + instance_type = "t2.micro" + # Added below line + iam_instance_profile = aws_iam_instance_profile.example_profile.name + root_block_device { volume_type = "gp3" @@ -84,5 +88,4 @@ resource "aws_instance" "web" { tags = { Name = "${local.project}" } - } \ No newline at end of file