operateguide / 40.AKS
프로젝트: astro-sub1
원본 경로: operateguide/40.AKS.md
AKS 설정(설정전)
1. 개요
AKS 접속 하기 위한 설정 방법에 대해 가이드 한다. Azure CLI tool 로 먼저 로그인하여 인증한후 AKS 접속 설정을 진행한다.
2. Azure CLI 설치 및 로그인
Azure CLI가 설치되어 있지 않다면 Azure CLI 설치 가이드에서 설치한다.
터미널을 열고 다음 명령어를 입력하여 Azure에 로그인한다.
$ az login --use-device-code
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code NAZN54T73 to authenticate.
Retrieving tenants and subscriptions for the selection...
[Tenant and subscription selection]
No Subscription name Subscription ID Tenant
----- ------------------- ------------------------------------ --------
[1] * ABC-Lab bbe8692f-000e-471b-ba79-c5eec94ca3d0 기본 디렉터리
The default is marked with an *; the default tenant is '기본 디렉터리' and subscription is 'ABC-Lab' (bbe8692f-000e-471b-ba79-c5eec94ca3d0).
Select a subscription and tenant (Type a number or Enter for no changes): 1
Tenant: 기본 디렉터리
Subscription: ABC-Lab (bbe8692f-000e-471b-ba79-c5eec94ca3d0)
[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=2271236
- 확인
# 구독 확인
$ az account list -o table
Name CloudName SubscriptionId TenantId State IsDefault
----------- ----------- ------------------------------------ ------------------------------------ ------- -----------
ABC-Lab AzureCloud bbe8692f-000e-471b-ba79-c5eec94ca3d0 a3870566-f011-4691-aa51-5b988c51c03a Enabled True
# 리소스 그룹 확인
$ az group list -o table
Name Location Status
--------------------------------------------------- ------------- ---------
VisualStudioOnline-7D6B761D0F66415EBB1388A39DE1872D southeastasia Succeeded
VisualStudioOnline-8107C48B98EC4037B7693FB049632282 southeastasia Succeeded
NetworkWatcherRG koreacentral Succeeded
abclab-dev-rg koreacentral Succeeded
abclab-dev-aks-mc-rg koreacentral Succeeded
abc-lab-sm koreasouth Succeeded
3. AKS 연결
CLI 환경에서 AKS를 접속하기 위해서는 kubectl 이라는 CLI tool 이 필요하다.
1) kubectl CLI 설치
az aks install-cli 명령을 이용해서 kubectl CLI tool 을 설치(설치되어 있지 않은 경우에만 수행) 한다.
# kubectl cli 설치
$ az aks install-cli
# arm64 의 경우 위 명령어가 아닌 brew install 을 사용하여 설치(M1)
$ brew install kubectl
# 확인
$ kubectl version
Client Version: v1.29.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.8
2) AKS 연결
AKS 클러스터와 연결하기 위해서 Credential 설정작업을 수행한다.
# aks 목록 확인
$ az aks list -o table
Name Location ResourceGroup KubernetesVersion CurrentKubernetesVersion ProvisioningState Fqdn
-------------- ------------ --------------- ------------------- -------------------------- ------------------- -------------------------------------------------------------------
abclab-dev-aks koreacentral abclab-dev-rg 1.29 1.29.7 Succeeded abclab-dev-abclab-dev-rg-bbe869-appw72du.hcp.koreacentral.azmk8s.io
# Credential 설정
export RG_NAME=abclab-dev-rg
export AKS_CLUSTER_NAME=abclab-dev-aks
$ az aks get-credentials \
--name $AKS_CLUSTER_NAME \
--resource-group $RG_NAME
Merged "abclab-dev-aks" as current context in ~/.kube/config
# 확인
$ kubectl config view
...
3) use-context
local 환경에 k8s 접속정보가 한개 이상일 경우 use-context 명령으로 특정 k8s 를 선택할 수 있다.
# 확인
$ kubectl config view
# get-context
$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* abclab-dev-aks abclab-dev-aks clusterUser_abclab-dev-rg_abclab-dev-aks
...
# use-context
$ kubectl config use-context abclab-dev-aks
4. Sample App(userlist) 배포
Kubernetes 설정이 문제가 없는지 확인하기 위해서 Sample App 을 배포해 본다.
배포 테스트가 완료되면 해당 App 은 삭제한다.
신규 프로젝트를 구성시 아래 Yaml 을 참고하여 구성한다.
1) Namespace
# 1) Namespace
$ kubectl create ns temp
2) Deploy
# 2) deploy
$ cat <<EOF | kubectl -n temp apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: userlist
app.kubernetes.io/instance: userlist
name: userlist
spec:
replicas: 2
selector:
matchLabels:
app: userlist
template:
metadata:
labels:
app: userlist
spec:
# App Node Node Selector Set
nodeSelector:
nodepool: app
containers:
- image: docker.io/ssongman/userlist:v1
name: userlist
ports:
- containerPort: 8181
protocol: TCP
terminationGracePeriodSeconds: 30
EOF
3) Service
# 3) service
$ cat <<EOF | kubectl -n temp apply -f -
apiVersion: v1
kind: Service
metadata:
name: userlist-svc
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 8181
selector:
app: userlist
EOF
4) Ingress
# ingress
$ cat <<EOF | kubectl -n temp apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: userlist-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: "userlist.4.230.144.108.nip.io"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: userlist-svc
port:
number: 80
EOF
- host 명은 정식 도메인이 발급된 후 수정한다.
5) 접속 테스트
$ curl userlist.4.230.144.108.nip.io
6) Clean Up
# 개별 리소스 삭제
$ kubectl -n temp delete deploy userlist
$ kubectl -n temp delete svc userlist-svc
$ kubectl -n temp delete ingress userlist-ingress
# Namespace 삭제 (NS내 모든 리스소가 삭제됨)
$ kubectl delete ns temp