Skip to content
Open
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
27 changes: 27 additions & 0 deletions k8sb61/pods&svc/ingress-sample/ingressrule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: oneingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: a30f69f0aeddb49c2b90d3ebec46edcc-1446820740.ap-south-1.elb.amazonaws.com
http:
paths:

- path: /nginx
pathType: Prefix
backend:
service:
name: nginxsrv
port:
number: 80
- path: /tomcat
pathType: Prefix
backend:
service:
name: tomcatsrv
port:
number: 8080
51 changes: 51 additions & 0 deletions k8sb61/pods&svc/ingress-sample/nginx/deploy_hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

apiVersion: apps/v1
kind: Deployment
metadata:
name: deployappnginx
labels:
app: deployappnginx
spec:
replicas: 2 #desiredstate
strategy:
type: RollingUpdate
selector:
matchLabels:
app: deployappnginx
template:
metadata:
labels:
app: deployappnginx
spec:
containers:
- name: deployappnginx
image: nginx:latest
ports:
- containerPort: 80
protocol: TCP
resources:
requests:
memory: "64Mi"
cpu: "125m"
limits:
memory: "128Mi"
cpu: "250m"
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: deployappnginx
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 20
14 changes: 14 additions & 0 deletions k8sb61/pods&svc/ingress-sample/nginx/svc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

apiVersion: v1
kind: Service
metadata:
name: nginxsrv
spec:
type: ClusterIP
selector:
app: deployappnginx
ports:
- port: 80
targetPort: 80
name: http
protocol: TCP
52 changes: 52 additions & 0 deletions k8sb61/pods&svc/ingress-sample/tomcat/deploy_hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@


apiVersion: apps/v1
kind: Deployment
metadata:
name: deployapptomcat
labels:
app: deployapptomcat
spec:
replicas: 2 #desiredstate
strategy:
type: RollingUpdate
selector:
matchLabels:
app: deployapptomcat
template:
metadata:
labels:
app: deployapptomcat
spec:
containers:
- name: deployapptomcat
image: tomcat:latest
ports:
- containerPort: 8080
protocol: TCP
resources:
requests:
memory: "64Mi"
cpu: "125m"
limits:
memory: "128Mi"
cpu: "250m"
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: deployapptomcat
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 20
13 changes: 13 additions & 0 deletions k8sb61/pods&svc/ingress-sample/tomcat/svc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: tomcatsrv
spec:
type: ClusterIP
selector:
app: deployapptomcat
ports:
- port: 8080
targetPort: 8080
name: tomcat
protocol: TCP
56 changes: 56 additions & 0 deletions loopb61/count.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
provider "aws" {
region = "ap-south-1"
profile = "configs"
}


resource "aws_instance" "example" {
instance_type = "t3.micro"
ami = "ami-00ca570c1b6d79f36"
count = 2
}


### creating servers with different os
resource "aws_instance" "example2" {
instance_type = "t3.micro"
ami = var.ami_list[count.index]
count = length(var.ami_list)

}

variable "ami_list"{
default = ["ami-00ca570c1b6d79f36" , "ami-02b8269d5e85954ef"]
#0 #1
}


#creating users
variable "userlist" {
default = ["user1" , "user2" , "user3"]
}


resource "aws_iam_user" "userexample" {
name = var.userlist[count.index]
count = length(var.userlist)

}



/* output "instanceip" {
value = [
for amiid in var.ami_list :
aws_instance.example2[amiid].public_ip
]

} */

/* output "instanceip" {
value = [
for amiid in var.ami_list :
aws_instance.example2[amiid].id
]

} */
34 changes: 34 additions & 0 deletions loopb61/for_foreach.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


resource "aws_instance" "example3" {
instance_type = "t3.micro"
ami = each.value
for_each = toset(var.ami_foreach)
}

variable "ami_foreach" {

default = ["ami-00ca570c1b6d79f36" , "ami-02b8269d5e85954ef"]

}



resource "aws_iam_user" "userexample2" {
name = each.value
for_each = toset(var.username2)

}

variable "username2" {
default = ["user5" , "user4" , "user6"]
}

output "aws_id" {

value = [
for amiid in var.ami_foreach:
aws_instance.example3[amiid].id
]

}