728x90
반응형
> master node에 접속하여 폴더생성
[root@k8s-master ~]# mkdir -p /root/k8s-local-volume/1231
> dashboard 접속 후 Namespace[모든 네임스페이스] -> [+]버튼 -> [입력을 통해 생성] -> yaml 파일 붙여넣기 -> 업로드
▶ Namespace
apiVersion: v1
kind: Namespace
metadata:
name: anotherclass-123
labels:
part-of: k8s-anotherclass
managed-by: dashboard
▶ Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
replicas: 2
strategy:
type: RollingUpdate
template:
metadata:
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master
containers:
- name: api-tester-1231
image: 1pro/api-tester:v1.0.0
ports:
- name: http
containerPort: 8080
envFrom:
- configMapRef:
name: api-tester-1231-properties
startupProbe:
httpGet:
path: "/startup"
port: 8080
periodSeconds: 5
failureThreshold: 24
readinessProbe:
httpGet:
path: "/readiness"
port: 8080
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet:
path: "/liveness"
port: 8080
periodSeconds: 10
failureThreshold: 3
resources:
requests:
memory: "100Mi"
cpu: "100m"
limits:
memory: "200Mi"
cpu: "200m"
volumeMounts:
- name: files
mountPath: /usr/src/myapp/files/dev
- name: secret-datasource
mountPath: /usr/src/myapp/datasource
volumes:
- name: files
persistentVolumeClaim:
claimName: api-tester-1231-files
- name: secret-datasource
secret:
secretName: api-tester-1231-postgresql
▶ Service
apiVersion: v1
kind: Service
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
ports:
- port: 80
targetPort: http
nodePort: 31231
type: NodePort
▶ Configmap, Secret
apiVersion: v1
kind: ConfigMap
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
data:
spring_profiles_active: "dev"
application_role: "ALL"
postgresql_filepath: "/usr/src/myapp/datasource/postgresql-info.yaml"
---
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-postgresql
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
stringData:
postgresql-info.yaml: |
driver-class-name: "org.postgresql.Driver"
url: "jdbc:postgresql://postgresql:5431"
username: "dev"
password: "dev123"
▶ PVC, PV
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: anotherclass-123
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: kubectl
spec:
resources:
requests:
storage: 2G
accessModes:
- ReadWriteMany
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
version: 1.0.0
managed-by: dashboard
spec:
capacity:
storage: 2G
volumeMode: Filesystem
accessModes:
- ReadWriteMany
local:
path: "/root/k8s-local-volume/1231"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [k8s-master]}
▶ HPA
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
namespace: anotherclass-123
name: api-tester-1231-default
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-tester-1231
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
behavior:
scaleUp:
stabilizationWindowSeconds: 120
> Object
- Namespace : Object를 그룹핑
- Deployment : pod를 만들고, 업데이트
- Configmap : pod에 환경변수 값 제공
- PV(Persistent Volume) : 데이터 용량 pool
- PVC(Persistent Volume Claim) : 데이터 용량 요구 명세결
- Service : pod의 트래픽 연결
- HPA(Horizontal Pod Autoscailing) : 부하에 따라 pod 조절
> Lable / Selector / Naming
- selector와 labels를 연결할때 selector ⊂ labels 관계여야 한다.
- selector에 labels을 기입할때 name이 workspace내에서 유니크 하기때문에 name만 기입하여도 됨.
728x90
반응형
'Container > Kubernetes' 카테고리의 다른 글
[Kubernetes] Application 기능으로 이해하기 - Deployment (0) | 2024.06.05 |
---|---|
[Kubernetes] Application 기능으로 이해하기 - PV/PVC (0) | 2024.06.05 |
[Kubernetes] Application 기능으로 이해하기 - Configmap, Secret (0) | 2024.05.29 |
[Kubernetes] Application 기능으로 이해하기 - Probe (0) | 2024.05.28 |
[Kubernetes] 표준 생태계 (0) | 2024.05.23 |