kubernetes object = API resource
1) kubectl api-resources
: api resource 확인
2) nodepadd++에서 yaml 코드 작성
apiVersion: v1
kind: Pod
metadata:
name: mynode-pod
labels:
app: myapp
spec:
containers:
- image: juliy9812/mynode:1.0
name: mynode-container
ports:
- containerPort: 8000
3) yamlint.com에서 검증
4) vi mynode.yaml
5) kubectl apply
kubectl apply -f mynode.yaml
: yaml 코드 적용
6) 할당된 ip 확인
kubectl get pod -o wide
: 생성된 pod 확인
7) check
curl 할당받은ip : 8000
8) 외부 server에서 연결 작업
apiVersion: v1
kind: Service
metadata:
name: mynode-svc
spec:
selector:
app: myapp
ports:
- port: 8800
targetPort: 8000
externalIPs:
- 192.168.56.101
curl 외부ip:8800
을 통해 같은 값이 나오는지 확인[ 주제 ] nginx pod 생성
1) CentOS 기반으로 생성
- nginx:1.23-alpine 이미지를 이용하여 pod(pod명: nginx-pod)를 생성하고 Service(서비스명: nginx-svc)에 연결하세요.
- 생성 후 podIP와 service clusterIP를 이용해 curl test 수행해 보세요
- nginx Pod내에 있는 container에 index.html을 복사하여 초기 화면을 변경하세요
~] # vi index.html # html 코드 제공
~] # kubectl cp index.html nginx-pod:/usr/share/nginx/html/index.html
2) GKE를 이용하여 public IP를 받아서 생성
[ 결과 ]
Welcome to nginx! 에서 검정색 index.html 화면으로 변경
### nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- image: nginx:1.23-alpine
name: mynginx-container
ports:
- containerPort: 8002
### nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
selector:
app: nginx
ports:
- port: 9000
targetPort: 8002
externalIPs:
- 192.168.56.102
apiVersion: v1
kind: Pod
metadata:
name: mongo-pod
labels:
app: hi-mongo
spec:
containers:
- image: mongo:4.0
name: mongodb-container
ports:
- containerPort: 27017
apiVersion: v1
kind: Service
metadata:
name: monbo-svc
spec:
selector:
app: hi-mongo
ports:
- port: 37017
targetPort: 27017
externalIPs:
- 192.168.56.102
mysql db 와 연동
apiVersion: v1
kind: Pod
metadata:
name: mydb-pod
labels:
app: mydb57
spec:
containers:
- image: mysql:5.7
name: mydb-container
env:
- name: MYSQL_ROOT_PASSWORD
value: k8s-pass#
ports:
- containerPort: 3306
apiVersion: v1
kind: Pod
metadata:
name: goapp-pod
labels:
app: hi-goapp
spec:
containers:
- name: goapp-container
image: juliy9812/goapp:1.0
ports:
- containerPort: 9090
---
apiVersion: v1
kind: Service
metadata:
name: goapp-svc
spec:
selector:
app: hi-goapp
ports:
- port: 9090
targetPort: 9090
type: LoadBalancer