{EKS}Amazon EKS の開始方法 - eksctl

https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/getting-started-eksctl.html

https://adamtheautomator.com/aws-eks-cli/

 

-- 1. コマンド等のインストール

-- 1.1 aws cli version 2 インストール

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version


-- 1.2 jqインストール
sudo yum -y install jq


-- 1.3 kubectlインストール
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
curl -o kubectl.sha256 https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl.sha256
openssl sha1 -sha256 kubectl
cat kubectl.sha256

chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
kubectl version --short --client


-- 1.4 eksctlインストール

curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version

 

-- 2.  Amazon EKS クラスターとノードを作成する

eksctl create cluster \
--name eks01 \
--region ap-northeast-1 \
--version 1.21 \
--fargate


※CloudFormationでスタック作成を確認

時間がかかる

 

-- 3. リソースを表示する

kubectl get nodes -o wide
kubectl get pods --all-namespaces -o wide

 

-- 4. 動作確認

sudo yum install -y git
git clone https://github.com/Adam-the-Automator/aws-eks-cli.git
cd aws-eks-cli
kubectl apply -f ./nginx-svc.yaml

kubectl get service
kubectl apply -f ./nginx-deployment.yaml

kubectl get deployment
kubectl get pod
kubectl get node

 

 

-- 5. クリーンアップ


eksctl delete cluster \
--name eks01 \
--region ap-northeast-1

 

※CloudFormationでスタック削除を確認

 

 

SQL Serverクライアント

(20)
https://docs.microsoft.com/ja-jp/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15

※(22)はリポジトリパスを修正してもエラー発生

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

sudo apt update 

sudo apt install -y mssql-tools unixodbc-dev


echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bash_profile


sqlcmd -S 192.168.137.61 -U sa -d test

(11)

apt update
apt install curl

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

curl https://packages.microsoft.com/config/debian/11/prod.list | tee /etc/apt/sources.list.d/msprod.list

apt update 

apt install -y mssql-tools unixodbc-dev


echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bash_profile


sqlcmd -S 192.168.137.61 -U sa -d test

 

 

(7)

yum update -y


curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo

yum install -y mssql-tools unixODBC-devel


echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bash_profile

sqlcmd -S 192.168.137.61 -U sa -d test

 

(2019)


https://docs.microsoft.com/ja-jp/sql/ssms/download-sql-server-management-studio-ssms?redirectedfrom=MSDN&view=sql-server-ver15

  日本語版をインストール

sqlcmd -S 192.168.137.61 -U sa -d test

Kubernetesインストール(シングル) 2022年5月版

https://www.gremlin.com/community/tutorials/how-to-create-a-kubernetes-cluster-on-ubuntu-16-04-with-kubeadm-and-weave-net/

mmm167: Ubuntu20 Kubernetes master node
mmm169: Ubuntu20 Kubernetes worker node


前提:
CPU数=2
メモリ 2G

※インストール後の作業はmaster nodeから一般ユーザでおこなう


--(1) masterとworkerの共通作業

sudo su -

apt update && apt install -y apt-transport-https

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF

apt update

apt install -y kubelet=1.16.1-00 kubeadm=1.16.1-00 kubectl=1.16.1-00 docker.io

cat /etc/fstab
sed -i '/swap/ s/^\(.*\)$/#\1/g' /etc/fstab
cat /etc/fstab
swapoff -a

 


--(2) master nodeの作成

kubeadm init

 

最後に表示される下記のような出力をコピーペーストして保存。あとでworker nodeで実行する

-- kubeadm join 172.31.29.183:6443 --token 8dzpqk.hh6b8zloz8gx8d0n \
--     --discovery-token-ca-cert-hash sha256:da4d2fad9f16bd9bd3a2ffec62ccff6f5683660bf84aa55cc2cb620d59b62939
    

exit

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


curl -o weave.yaml https://cloud.weave.works/k8s/v1.9/net.yaml

cat weave.yaml
kubectl apply -f weave.yaml


kubectl get nodes
kubectl get pod --all-namespaces
kubectl get nodes -o wide


--(3) worker nodeの作成

sudo su -

kubeadm join 172.31.29.183:6443 --token 8dzpqk.hh6b8zloz8gx8d0n \
    --discovery-token-ca-cert-hash sha256:da4d2fad9f16bd9bd3a2ffec62ccff6f5683660bf84aa55cc2cb620d59b62939
    

---------------------
master nodeで確認

kubectl get nodes
kubectl get pod --all-namespaces

---------------------

 

 

{ALB}Auto Scaling with ALB

https://qiita.com/miyuki_samitani/items/e06c8cdcfe8a8df226e5
https://beyondjapan.com/blog/2017/03/aws-cli-autoscaling/

ロードバランサー
  |
  |---> リスナー
  |
ターゲットグループ
  ↓
オートスケーリンググループ
  ↑
起動設定

 

-- 1. コマンド等のインストール

-- 1.1 aws cli version 2 インストール

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

aws --version

-- 1.2 jqインストール
sudo yum -y install jq

 

 

-- 2. ロードバランサーの作成
※internal-ALBを作成
※AZはap-northeast-1a と ap-northeast-1c


aws elbv2 create-load-balancer \
--name alb01  \
--subnets subnet-11111111111111111  subnet-22222222222222222 \
--security-groups sg-33333333333333333 \
--scheme internal


aws elbv2 describe-load-balancers
aws elbv2 describe-load-balancers| jq -r .LoadBalancers.LoadBalancerArn

 

 

-- 3. ターゲットグループの作成

aws elbv2 create-target-group \
--name target01 \
--protocol HTTP \
--port 80 \
--vpc-id vpc-44444444444444444 \
--ip-address-type ipv4 \
--target-type instance

aws elbv2 describe-target-groups
aws elbv2 describe-target-groups| jq -r .TargetGroups.TargetGroupArn

aws elbv2 describe-target-group-attributes \
--target-group-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:targetgroup/target01/5555555555555555

 


-- 4. 起動設定の作成


vim a.sh

#!/bin/bash
yum -y update
yum -y install httpd
systemctl start httpd
systemctl enable httpd
echo $(hostname) > /var/www/html/index.html


aws autoscaling create-launch-configuration \
--launch-configuration-name lc01 \
--image-id ami-0404778e217f54308 \
--key-name key1 \
--security-groups sg-33333333333333333 \
--instance-type t3.nano \
--user-data file://a.sh


aws autoscaling describe-launch-configurations

 

-- 5. オートスケーリンググループの作成

aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name asg01 \
--launch-configuration-name lc01 \
--min-size 1 \
--max-size 2 \
--desired-capacity 1 \
--availability-zones "ap-northeast-1a" "ap-northeast-1c" \
--target-group-arns "arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:targetgroup/target01/5555555555555555" \
--vpc-zone-identifier "subnet-11111111111111111,subnet-22222222222222222"

 

aws autoscaling describe-auto-scaling-groups

 

 


-- 6. スケーリングポリシーを作成する

aws autoscaling describe-policies

 

aws autoscaling put-scaling-policy \
--auto-scaling-group-name asg01 \
--policy-name policy01 \
--policy-type TargetTrackingScaling \
--target-tracking-configuration '{
                "PredefinedMetricSpecification": {
                    "PredefinedMetricType": "ASGAverageCPUUtilization"
                },
                "TargetValue": 30.0,
                "DisableScaleIn": false
            }'


アラームが2個自動で作成される

 


-- 7. リスナーの作成

aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:loadbalancer/app/alb01/6666666666666666 \
--protocol HTTP \
--port 80  \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:targetgroup/target01/5555555555555555


aws elbv2 describe-listeners \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:loadbalancer/app/alb01/6666666666666666

aws elbv2 describe-listeners \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:loadbalancer/app/alb01/6666666666666666 | jq -r .Listeners[].ListenerArn

 


curl -v -X GET http://internal-alb01-0000000000.ap-northeast-1.elb.amazonaws.com

 

-- 8. 動作確認

ターゲットのEC2にログインして実行

yes > /dev/null &


aws elbv2 describe-target-health \
--target-group-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:targetgroup/target01/5555555555555555

 

-- 9. クリーンアップ


-- リスナーの削除

aws elbv2 describe-listeners \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:loadbalancer/app/alb01/6666666666666666


aws elbv2 delete-listener \
--listener-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:listener/app/alb01/6666666666666666/7777777777777777

-- ロードバランサーの削除

aws elbv2 describe-load-balancers

aws elbv2 delete-load-balancer \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:loadbalancer/app/alb01/6666666666666666


-- ターゲットグループの削除

aws elbv2 describe-target-groups


aws elbv2 delete-target-group \
--target-group-arn arn:aws:elasticloadbalancing:ap-northeast-1:999999999999:targetgroup/target01/5555555555555555

 

 


-- オートスケーリンググループの削除

aws autoscaling describe-auto-scaling-groups

aws autoscaling detach-instances \
--instance-ids "i-88888888888888888" "i-aaaaaaaaaaaaaaaaa" \
--auto-scaling-group-name asg01 \
--no-should-decrement-desired-capacity


aws autoscaling delete-auto-scaling-group \
--auto-scaling-group-name asg01 

 


-- 起動設定の削除

aws autoscaling describe-launch-configurations

aws autoscaling delete-launch-configuration \
--launch-configuration-name lc01


-- EC2インスタンスの削除

aws ec2 describe-instances

aws ec2 terminate-instances --instance-ids i-88888888888888888
aws ec2 terminate-instances --instance-ids i-aaaaaaaaaaaaaaaaa

 

 

 

PostgreSQLクライアント

(22)

sudo apt update -y

sudo apt install postgresql-client-14

 

psql -h 192.168.137.70 -U postgres test

 

(11)

apt update -y

apt install postgresql-client


psql -h 192.168.137.70 -U postgres test

 

 

(7)

yum update -y

yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

yum -y search postgresql14
yum -y install postgresql14


psql -h 192.168.137.70 -U postgres test

 

 

(2019)

https://www.postgresql.org/download/windows/


Select Components
Command Line Toolsのみ選択


PATH追加
C:\Program Files\PostgreSQL\14\bin


psql -h 192.168.137.70 -U postgres test