2023. 10. 31. 15:50ㆍk8s
이론
cluster ip : 내부 통신용, 내부 자원 공유 - default
node port : 30000 - 32767 외부 서비스 가능
http-go-v1.yml 파일 생성
apiVersion: v1
kind: Pod
metadata:
name: http-go
labels:
app: http-go
spec:
containers:
- name: http-go
image: jingukang/http-go
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: http-go-svc
spec:
selector:
app: http-go
ports:
- port: 80
targetPort: 8080
cluster ip를 이용한 접속
kubectl create -f http-go-v1.yml
kubectl exec http-go -- curl 10.111.94.35:80 -s
http-go-deploy.yml 파일 생성
kubectl create deploy --image=jingukang/http-go http-go --port=8080 --dry-run=client -o yaml > http-go-deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: http-go
name: http-go
spec:
replicas: 1
selector:
matchLabels:
app: http-go
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: http-go
spec:
containers:
- image: jingukang/http-go
name: http-go
ports:
- containerPort: 8080
resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: http-go-svc
spec:
selector:
app: http-go
ports:
- port: 80
targetPort: 8080
로드 밸런서 실습
kubectl create -f http-go-deploy.yml
kubectl exec http-go-55b78f6df8-jdhql -- curl 10.104.239.122 -s
kubectl scale deploy http-go --replicas=5
kubectl describe svc | grep Endpoints:
kubectl exec http-go-55b78f6df8-72b8r -- curl 10.104.239.122 -s
kubectl exec http-go-55b78f6df8-jdhql -- curl 10.104.239.122 -s
kubectl exec http-go-55b78f6df8-jm4sh -- curl 10.104.239.122 -s
kubectl exec http-go-55b78f6df8-tspg5 -- curl 10.104.239.122 -s
kubectl exec http-go-55b78f6df8-v28h7 -- curl 10.104.239.122 -s
kubectl run -it --rm --image busybox bash
wget -O- -q 10.104.239.122
트러블 슈팅
kubectl run -it --rm --image busybox bash
을 시도할 때 ImagePull이 안 되는 경우가 있다. 이 역시 pulling에 제한 횟수 때문에 생기는 오류다.
이를 해결하기 위해 아래와 같이 개인 registry 등록을 먼저하자.
kubectl create secret docker-registry test --docker-username=<username> --docker-password=<password>
다시 아래 명령을 시도하면 busybox가 잘 작동되는 것을 확인할 수 있다.
kubectl run -it --rm --image busybox --overrides='
{
"spec": {
"imagePullSecrets": [
{
"name": "test"
}
]
}
}' -- bash
'k8s' 카테고리의 다른 글
인증서 갱신 (0) | 2024.07.29 |
---|---|
Endpoint (1) | 2023.10.31 |
etcd (0) | 2023.10.31 |
Kubernetes 클러스터의 구성요소 (0) | 2023.10.31 |
네임 스페이스 요구명세서 실습 (0) | 2023.10.31 |