diff --git a/k8sb61/pods&svc/ingress-sample/ingressrule.yml b/k8sb61/pods&svc/ingress-sample/ingressrule.yml new file mode 100644 index 0000000..cab7d91 --- /dev/null +++ b/k8sb61/pods&svc/ingress-sample/ingressrule.yml @@ -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 \ No newline at end of file diff --git a/k8sb61/pods&svc/ingress-sample/nginx/deploy_hpa.yml b/k8sb61/pods&svc/ingress-sample/nginx/deploy_hpa.yml new file mode 100644 index 0000000..5a588da --- /dev/null +++ b/k8sb61/pods&svc/ingress-sample/nginx/deploy_hpa.yml @@ -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 \ No newline at end of file diff --git a/k8sb61/pods&svc/ingress-sample/nginx/svc.yml b/k8sb61/pods&svc/ingress-sample/nginx/svc.yml new file mode 100644 index 0000000..4be0867 --- /dev/null +++ b/k8sb61/pods&svc/ingress-sample/nginx/svc.yml @@ -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 \ No newline at end of file diff --git a/k8sb61/pods&svc/ingress-sample/tomcat/deploy_hpa.yml b/k8sb61/pods&svc/ingress-sample/tomcat/deploy_hpa.yml new file mode 100644 index 0000000..e108c10 --- /dev/null +++ b/k8sb61/pods&svc/ingress-sample/tomcat/deploy_hpa.yml @@ -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 \ No newline at end of file diff --git a/k8sb61/pods&svc/ingress-sample/tomcat/svc.yml b/k8sb61/pods&svc/ingress-sample/tomcat/svc.yml new file mode 100644 index 0000000..db31c83 --- /dev/null +++ b/k8sb61/pods&svc/ingress-sample/tomcat/svc.yml @@ -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 \ No newline at end of file diff --git a/loopb61/count.tf b/loopb61/count.tf new file mode 100644 index 0000000..e9c0166 --- /dev/null +++ b/loopb61/count.tf @@ -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 + ] + +} */ \ No newline at end of file diff --git a/loopb61/for_foreach.tf b/loopb61/for_foreach.tf new file mode 100644 index 0000000..dab5513 --- /dev/null +++ b/loopb61/for_foreach.tf @@ -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 + ] + + } \ No newline at end of file