#!/bin/bash
timedatectl set-timezone Asia/Seoul
hostnamectl set-hostname eks-server
cd /tmp
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
mv ./kubectl /usr/local/bin
echo "source <(kubectl completion bash)" >> /home/ec2-user/.bashrc
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
mv /tmp/eksctl /usr/local/bin
[ec2-user@eks-server ~]$ sudo passwd ec2-user
sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication no
$ eksctl create cluster --name EKS-CLUSTER --region ap-northeast-2 --version 1.21 --vpc-public-subnets subnet-025da2c754a6dd49b,subnet-082ffc23ff8d32265 --without-nodegroup
$ eksctl create nodegroup \
--cluster EKS-CLUSTER \
--region ap-northeast-2 \
--name NODEGROUP \
--node-type t2.micro \
--nodes 4 \
--nodes-min 4 \
--nodes-max 8 \
--ssh-access \
--ssh-public-key docker-key
sudo vi /etc/ansible/hosts
[eks-server]
10.24.47.232
$ ssh-copy-id 10.24.47.232 //eks ip에 키 전달
vi build.yaml
- hosts: ansible-server
tasks:
- name: remove docker image
command: docker rmi -f halilinux/mytomcat:latest
- name: create docker image
command: docker build -t halilinux/mytomcat:latest .
args:
chdir: /opt/docker
- name: push docker image
command: docker push halilinux/mytomcat:latest
$ ansible-playbook build.yml
vi kube-deploy-svc.yml
- hosts: eks-server
tasks:
- name: remove deploy
command: kubectl delete -f /home/ec2-user/test/deployment.yaml
ignore_errors: yes
- name: kube deploy
command: kubectl apply -f /home/ec2-user/test/deployment.yaml
- name: kube svc
command: kubectl apply -f /home/ec2-user/test/svc.yaml
- name: update
command: kubectl rollout restart deployment/web-site-deployment
vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-site-deployment
spec:
replicas: 2
selector:
matchLabels:
app: web-site-deployment
template:
metadata:
name: web-site-deployment
labels:
app: web-site-deployment
spec:
containers:
- name: web-site-deployment-container
image: seozzang3/mytomcat:latest
imagePullPolicy: Always
vi svc.yaml
apiVersion: v1
kind: Service
metadata:
name: loadbalancer-service-deployment
spec:
type: LoadBalancer
selector:
app: web-site-deployment
ports:
- protocol: TCP
port: 8080
targetPort: 8080
[ec2-user@eks-server test]$ kubectl apply -f deployment.yaml
deployment.apps/web-site-deployment created
[ec2-user@eks-server test]$ kubectl apply -f svc.yaml
service/loadbalancer-service-deployment created
-> 실행하면
[ec2-user@ansible-server docker]$ ansible-playbook kube-deploy-svc.yml
-> 빨간 부분은 지울게 없어서 오류난 것
-> ignore를 안썼으면 저기서 멈춤
cd /opt/docker;
ansible-playbook build.yml;
sleep 10;
ansible-playbook kube-deploy-svc.yml
-> 지금 빌드
$ rm -rf hello_world/
$ git clone https://github.com/seo369/hello-world.git
$ cd hello_world/
$ cd webapp/src/main/webapp/
$ vi index.jsp -> 내용 변경
$ git add .
$ git commit -, "test1"
$ git push origin master
-> 빌드유발 해놔서 자동 빌드
-> 변경내용 잘 나옴
$ kubectl delete all -all
$ eksctl delete cluster EKS-CLUSTER --region ap-northeast-2