vi deployment-config01.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: configapp
labels:
app: configapp
spec:
replicas: 1
selector:
matchLabels:
app: configapp
template:
metadata:
labels:
app: configapp
spec:
containers:
- name: testapp
image: nginx
ports:
- containerPort: 8080
env:
- name: DEBUG_LEVEL # ์ปจํ
์ด๋ ์์์์ ๋ณ์๋ช
valueFrom:
configMapKeyRef:
name: config-dev
key: DEBUG_INFO
---
apiVersion: v1
kind: Service
metadata:
labels:
app: configapp
name: configapp-svc
namespace: default
spec:
type: NodePort
ports:
- nodePort: 30800
port: 8080
protocol: TCP
targetPort: 80
selector:
app: configapp
[root@master1 configmap]# kubectl apply -f deployment-config01.yaml
[root@master1 configmap]# kubectl describe pod configapp-c9bb7b748-2ft9p
[root@master1 configmap]# kubectl exec -it configapp-c9bb7b748-2ft9p -- bash
# vi configmap-wordpress.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: config-wordpress
namespace: default
data:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: mode1752
MYSQL_DATABASE: wordpress
MYSQL_USER: wpuser
MYSQL_PASSWORD: wppass
# kubectl apply -f configmap-wordpress.yaml
# kubectl describe configmaps config-wordpress
vi mysql-pod-svc.yaml
apiVersion: v1
kind: Pod
metadata:
name: mysql-pod
labels:
app: mysql-pod
spec:
containers:
- name: mysql-container
image: mysql:5.7
envFrom: ## ์ปจํผ๊ทธ๋งต ์ค์ ์ ์ฒด๋ฅผ ํ๊บผ๋ฒ์ ๋ถ๋ฌ์์ ์ฌ์ฉํ๊ธฐ
- configMapRef:
name: config-wordpress
ports:
- containerPort: 3306
---
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
spec:
type: ClusterIP
selector:
app: mysql-pod
ports:
- protocol: TCP
port: 3306
targetPort: 3306
[root@master1 configmap]# kubectl apply -f mysql-pod-svc.yaml
[root@master1 configmap]# kubectl get all
vi wordpress-pod-svc.yaml
apiVersion: v1
kind: Pod
metadata:
name: wordpress-pod
labels:
app: wordpress-pod
spec:
containers:
- name: wordpress-container
image: wordpress
env:
- name: WORDPRESS_DB_HOST
value: mysql-svc:3306
- name: WORDPRESS_DB_USER
valueFrom:
configMapKeyRef:
name: config-wordpress
key: MYSQL_USER
- name: WORDPRESS_DB_PASSWORD
valueFrom:
configMapKeyRef:
name: config-wordpress
key: MYSQL_PASSWORD
- name: WORDPRESS_DB_NAME
valueFrom:
configMapKeyRef:
name: config-wordpress
key: MYSQL_DATABASE
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: wordpress-svc
spec:
type: LoadBalancer
# externalIPs:
# - 192.168.2.0
selector:
app: wordpress-pod
ports:
- protocol: TCP
port: 80
targetPort: 80
# vi mysql-deploy-svc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deploy
labels:
app: mysql-deploy
spec:
replicas: 1
selector:
matchLabels:
app: mysql-deploy
template:
metadata:
labels:
app: mysql-deploy
spec:
containers:
- name: mysql-container
image: mysql:5.7
envFrom:
- configMapRef:
name: config-wordpress
ports:
- containerPort: 3306
---
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
spec:
type: ClusterIP
selector:
app: mysql-deploy
ports:
- protocol: TCP
port: 3306
targetPort: 3306
[root@master1 configmap]# kubectl apply -f mysql-deploy-svc.yaml
[root@master1 configmap]# kubectl delete pod mysql-pod
pod "mysql-pod" deleted
[root@master1 configmap]# kubectl delete pod wordpress-pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-deploy
labels:
app: wordpress-deploy
spec:
replicas: 3
selector:
matchLabels:
app: wordpress-deploy
template:
metadata:
labels:
app: wordpress-deploy
spec:
containers:
- name: wordpress-container
image: wordpress
env:
- name: WORDPRESS_DB_HOST
value: mysql-svc:3306
- name: WORDPRESS_DB_USER
valueFrom:
configMapKeyRef:
name: config-wordpress
key: MYSQL_USER
- name: WORDPRESS_DB_PASSWORD
valueFrom:
configMapKeyRef:
name: config-wordpress
key: MYSQL_PASSWORD
- name: WORDPRESS_DB_NAME
valueFrom:
configMapKeyRef:
name: config-wordpress
key: MYSQL_DATABASE
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: wordpress-svc
spec:
type: LoadBalancer
# externalIPs:
# - 192.168.2.0
selector:
app: wordpress-deploy
ports:
- protocol: TCP
port: 80
targetPort: 80
# kubectl apply -f wordpress-deploy-svc.yaml
# kubectl get all -o wide
[root@master1 configmap]# kubectl exec -it wordpress-deploy-57787cfd48-btk9r -- bash
root@wordpress-deploy-57787cfd48-btk9r:/var/www/html#
root@wordpress-deploy-57787cfd48-btk9r:/var/www/html#
root@wordpress-deploy-57787cfd48-btk9r:/var/www/html# ls -al
AZURE resource group๊ฐ์ ๋๋
# kubectl get namespaces
# kubectl config get-contexts kubernetes-admin@kubernetes
# kubectl create namespace test-namespace
# kubectl run nginx-pod1 --image=nginx -n test-namespace
# kubectl get pod -n test-namespace
# kubectl config set-context kubernetes-admin@kubernetes --namespace=test-namespace ##default namespace๋ก ์ค์
[root@master1 ~]# kubectl config get-contexts kubernetes-admin@kubernetes
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kubernetes-admin@kubernetes kubernetes kubernetes-admin test-namespace
[root@master1 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-pod1 1/1 Running 0 4m
# kubectl expose pod nginx-pod1 --type=LoadBalancer --name loadbalancer --port=80 ##metallb๋๋ถ์ external ipํ์ง ์์๋ ๋จ.
[root@master1 ~]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginx-pod1 1/1 Running 0 7m40s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/loadbalancer LoadBalancer 10.102.29.192 192.168.56.103 80:31344/TCP 10s
[root@master1 ~]# kubectl delete namespace test-namespace
[root@master1 ~]# kubectl get all
No resources found in test-namespace namespace.
[root@master1 ~]# kubectl config set-context kubernetes-admin@kubernetes --namespace= ## default๋ก ๋์๊ฐ๊ธฐ.
[root@master1 ~]# kubectl config get-contexts kubernetes-admin@kubernetes
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kubernetes-admin@kubernetes kubernetes kubernetes-admin
์ด๋๋ถ์(nameserver)๊ฐ ์ ์ฒด ํด๋ฌ์คํฐ ์ฉ๋์ ์ ์ ํ ์ ์์ผ๋๊น ์ฉ๋์ ์ ํด๋์. =>resource Quota
[root@master1 ~]# kubectl create ns my-ns
namespace/my-ns created
[root@master1 ~]# kubectl get ns
NAME STATUS AGE
default Active 26h
kube-flannel Active 26h
kube-node-lease Active 26h
kube-public Active 26h
kube-system Active 26h
metallb-system Active 21h
my-ns Active 13s
# vi sample-resourcequota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: sample-resourcequota
namespace: my-ns
spec:
hard:
count/pods: 5 ## pod 5๊ฐ ์ด์ ๋ชป๋ง๋ค๊ฒ
kubectl describe resourcequotas sample-resourcequota -n my-ns
kubectl run new-nginx --image=nginx -n my-ns
kubectl get po -n my-ns
[root@master1 resourcequota]# kubectl get resourcequotas -n my-ns
NAME AGE REQUEST LIMIT
sample-resourcequota 96s count/pods: 0/5
[root@master1 resourcequota]# kubectl run new-nginx --image=nginx -n my-ns
pod/new-nginx created
[root@master1 resourcequota]# kubectl run new-nginx1 --image=nginx -n my-ns
pod/new-nginx1 created
[root@master1 resourcequota]# kubectl run new-nginx12 --image=nginx -n my-ns
pod/new-nginx12 created
[root@master1 resourcequota]# kubectl run new-nginx3 --image=nginx -n my-ns
pod/new-nginx3 created
[root@master1 resourcequota]# kubectl run new-nginx4 --image=nginx -n my-ns
pod/new-nginx4 created
[root@master1 resourcequota]# kubectl run new-nginx5 --image=nginx -n my-ns
Error from server (Forbidden): pods "new-nginx5" is forbidden: exceeded quota: sample-resourcequota, requested: count/pods=1, used: count/pods=5, limited: count/pods=5
[root@master1 resourcequota]# kubectl get po -n my-ns
NAME READY STATUS RESTARTS AGE
new-nginx 1/1 Running 0 34s
new-nginx1 1/1 Running 0 30s
new-nginx12 1/1 Running 0 26s
new-nginx3 1/1 Running 0 21s
new-nginx4 1/1 Running 0 17s
5๊ฐ ์ด๊ณผ๋ก ์์ฑ ์๋จ.
[root@master1 resourcequota]# vi sample-resourcequota.yaml
->์ฌ๊ธฐ์ ์์
[root@master1 resourcequota]# kubectl edit resourcequotas sample-resourcequota -n my-ns
-> spec ๋ถ๋ถ ์์
๋๋ฆฐ๋ค์์ ์ค์ธ๋ค๊ณ Pod๊ฐ ์ญ์ ๋์ง๋ ์์ง๋ง ๋ค์ ๋ ์์ฑ์ ์๋จ.
[root@master1 resourcequota]# kubectl config set-context kubernetes-admin@kubernetes --namespace=my-ns
Context "kubernetes-admin@kubernetes" modified.
[root@master1 resourcequota]# kubectl config get-contexts kubernetes-admin@kubernetes
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kubernetes-admin@kubernetes kubernetes kubernetes-admin my-ns
vi sample-resourcequota-usable.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
name: sample-resourcequota-usable
spec:
hard:
requests.memory: 2Gi
requests.storage: 5Gi
sample-storageclass.storageclass.storage.k8s.io/requests.storage: 5Gi
requests.ephemeral-storage: 5Gi
requests.nvidia.com/gpu: 2
limits.cpu: 4
limits.ephemeral-storage: 10Gi
limits.nvidia.com/gpu: 4
[root@master1 resourcequota]# kubectl get resourcequotas
NAME AGE REQUEST LIMIT
sample-resourcequota 15m count/pods: 8/8
sample-resourcequota-usable 50s requests.ephemeral-storage: 0/5Gi, requests.memory: 0/2Gi, requests.nvidia.com/gpu: 0/2, requests.storage: 0/5Gi, sample-storageclass.storageclass.storage.k8s.io/requests.storage: 0/5Gi limits.cpu: 0/4, limits.ephemeral-storage: 0/10Gi, limits.nvidia.com/gpu: 0/4
โ๏ธ ์์ ํ ๋น์ ๋ฃ์ง ์์ ๊ฒฝ์ฐ -> error
vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
Error from server (Forbidden): error when creating "sample-pod.yaml": pods "sample-pod" is forbidden: failed quota: sample-resourcequota-usable: must specify limits.cpu,requests.memory
โ๏ธ ์์ ํ ๋น์ ๋ฃ์ ๊ฒฝ์ฐ
vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m" #1000milicore ; 1core
1์ฝ์ด๋ฅผ 5%~10% ์ฌ์ฉํ๊ฒ ๋ค. 50m;5%
๋ฉ๋ชจ๋ฆฌ๋ฅผ 64~128m ์ฌ์ฉํ๊ฒ ๋ค.
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
Error from server (Forbidden): error when creating "sample-pod.yaml": pods "sample-pod" is forbidden: exceeded quota: sample-resourcequota, requested: count/pods=1, used: count/pods=5, limited: count/pods=5
[root@master1 resourcequota]# kubectl edit resourcequotas sample-resourcequota
resourcequota/sample-resourcequota edited
-> spec "10"์ผ๋ก.
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
pod/sample-pod created
->์์ฑ ์ฑ๊ณต.
->์์ํ ๋น์์ ์ ํ์ ์์ง๋ง pod์ ํ์์ ๊ฑธ๋ฆผ. Pod ์ ํ ์์ ํ๊ณ pod ์์ฑ ์๋ฃ.
[root@master1 resourcequota]# kubectl delete pod sample-pod
[root@master1 resourcequota]# vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "3Gi"
cpu: "50m"
limits:
memory: "6Gi"
cpu: "100m"
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
Error from server (Forbidden): error when creating "sample-pod.yaml": pods "sample-pod" is forbidden: exceeded quota: sample-resourcequota-usable, requested: requests.memory=3Gi, used: requests.memory=0, limited: requests.memory=2Gi
->memory์ ํ์ผ๋ก ์ธํด ์์ฑ ์๋จ.
[root@master1 resourcequota]# vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "2Gi"
cpu: "50m"
limits:
memory: "6Gi"
cpu: "100m"
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
pod/sample-pod created
->2g๋ก ํ๋ฉด ๋ฌด๋ํ ์์ฑ
[root@master1 resourcequota]# vi sample-pod.yaml
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
The Pod "sample-pod" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)
->์ค๊ฐ์ ๋ฉ๋ชจ๋ฆฌ ๋ฐ๊พผ๊ฒ ์ ์ฉ๋์ง๋ ์์ (์์ ๋ถ๊ฐ), ์ง์ฐ๊ณ ๋ค์ ์์ฑ๋ง ๊ฐ๋ฅ.
[root@master1 resourcequota]# kubectl delete pod sample-pod
pod "sample-pod" deleted
[root@master1 resourcequota]# vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "1Gi"
cpu: "4050m"
limits:
memory: "6Gi"
cpu: "4100m"
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
Error from server (Forbidden): error when creating "sample-pod.yaml": pods "sample-pod" is forbidden: exceeded quota: sample-resourcequota-usable, requested: limits.cpu=4100m, used: limits.cpu=0, limited: limits.cpu=4
[root@master1 resourcequota]# vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "64Mi"
cpu: "3950m"
limits:
memory: "128Mi"
cpu: "4000m"
[root@master1 resourcequota]# kubectl apply -f sample-pod.yaml
pod/sample-pod created
[root@master1 resourcequota]# kubectl get pod
NAME READY STATUS RESTARTS AGE
sample-pod 0/1 Pending 0 6s
root@master1 resourcequota]# kubectl describe node worker2
node๋ฆฌ์์ค ๊ฐ์ํด์ ์์ฑํด์ผํจ.(๋ฆฌ์์ค ์ฟผํฐ๋ณด๋ค ์์คํ
์์์ด ์ฐ์ .)
์์คํ
์์๋ณด๋คํฌ๊ณ ๋ฆฌ์์ค์ฟผํฐ๋ณด๋ค ์์ ๊ฒฝ์ฐ pod ์์ฑ์ด ๋๊ธด ํ์ง๋ง Pending์ํ์์ ๋์ด๊ฐ์ง ์์.
[root@master1 resourcequota]# vi sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "64Mi"
cpu: "500m"
limits:
memory: "128Mi"
cpu: "1000m"
[root@master1 resourcequota]# kubectl get pod
NAME READY STATUS RESTARTS AGE
sample-pod 1/1 Running 0 3m26s
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-resource
spec:
replicas: 3
selector:
matchLabels:
app: sample-app
template:
metadata:
labels:
app: sample-app
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "100m"
[root@master1 resourcequota]# kubectl apply -f sample-resource.yaml
[root@master1 ~]# mkdir limitrange && cd $_
# vi sample-limitrange-container.yaml
apiVersion: v1
kind: LimitRange
metadata:
name: sample-limitrange-container
namespace: my-ns
spec:
limits: # ์ต๋ 2๊ฐ ํ๋ ์์ฑ, 1๊ฐ ๋ํ๋ฉด ์์ฑ ์๋จ.
- type: Container # ์ปจํ
์ด๋์ ๋ํ
default: # ๊ธฐ๋ณธ ์ต๋ Limits, ์ ํ ๋ฆฌ์์ค๊ฐ ๋ถ์กฑํ๋ฉด ์ปจํ
์ด๋๊ฐ ์์ฑ๋์ง ์๋๋ค.
memory: 512Mi
cpu: 500m
defaultRequest: # ์ง๊ธ ์ปจํ
์ด๋์ ์
ํ
ํ ๊ฐ. ์ง์ ์ ํ์ง ์์ ๊ฒฝ์ฐ ์ต์ ์ฉ๋, ์ต์ ํ๋ณด ์ฉ๋.
memory: 256Mi
cpu: 250m
max: # ์ง์ ์ค์ ํ ๊ฒฝ์ฐ ๊ฐ
memory: 1024Mi
cpu: 1000m
min:
memory: 128Mi
cpu: 125m
maxLimitRequestRatio: # Requests์ Limit์ ์ฐจ์ด ํ์ฉ ๋น์จ 2๋ฐฐ, ์ค๋ฒ ์ปค๋ฐ์ ํผํ ์ ์๋ค.
memory: 2
cpu: 2
[root@master1 limitrange]# kubectl apply -f sample-limitrange-container.yaml
limitrange/sample-limitrange-container created
[root@master1 limitrange]# kubectl describe limitranges sample-limitrange-container
[root@master1 limitrange]# vi sample-pod-limit.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod-limitrange
spec:
containers:
- name: nginx-container
image: nginx:1.16
[root@master1 limitrange]# kubectl apply -f sample-pod-limit.yaml
pod/sample-pod-limitrange created
[root@master1 limitrange]# kubectl get pod -o wide
-> ๋ฆฌ์์ค์ฟผํฐ์ ๋ฆฌ๋ฐ๋ ์ธ์ง ๊ฐ์ด ์ฌ์ฉํ ์ ์๋ค. => ์ปจํ ์ด๋ ๋ถ๋ถ์ ๊ตณ์ด ์์ ํ ๋นํ์ง ์์๋ ๋ฆฌ๋ฐ๋ ์ธ์ง์ ์ ์ ํ ํด๋์ผ๋ฉด ๋งค๋ฒ ๋ง๋ค๋๋ง๋ค ์ปจํ ์ด๋ ์ชฝ์ ์์ ์ ์ด์ค ํ์ ์๋ค.
[root@master1 limitrange]# kubectl describe pod sample-pod-limitrange
[root@master1 limitrange]# vi sample-pod-overrequest.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod-overrequest
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
cpu: 100m
limits:
cpu: 100m
[root@master1 limitrange]# kubectl apply -f sample-pod-overrequest.yaml
Error from server (BadRequest): error when creating "sample-pod-overrequest.yaml": Pod in version "v1" cannot be handled as a Pod: v1.Pod.Spec: v1.
-> ์์ฑ ์๋จ.
[root@master1 limitrange]# vi sample-pod-overrequest.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod-overrequest
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
cpu: 125m
limits:
cpu: 125m
[root@master1 limitrange]# kubectl apply -f sample-pod-overrequest.yaml
pod/sample-pod-overrequest created
-> ๋ฆฌ๋ฐ๋ ์ธ์ง์ ๋ง๊ฒ ํด์ฃผ๋ ์์ฑ ์๋ฃ.
CPU ๋ฆฌํ์คํธ์ ๋ฆฌ๋ฐ ์ฐจ์ด 2๋ฐฐ ์ด์
[root@master1 limitrange]# vi sample-pod-overratio.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod-overratio
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
cpu: 125m
limits:
cpu: 500m
[root@master1 limitrange]# kubectl apply -f sample-pod-overratio.yaml
Error from server (Forbidden): error when creating "sample-pod-overratio.yaml": pods "sample-pod-overratio" is forbidden: cpu max limit to request ratio per Container is 2, but provided ratio is 4.000000
-> ์์ฑ ์๋จ .
[root@master1 limitrange]# vi sample-pod-overratio.yaml
apiVersion: v1
kind: Pod
metadata:
name: sample-pod-overratio
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
cpu: 250m
limits:
cpu: 500m
[root@master1 limitrange]# kubectl apply -f sample-pod-overratio.yaml
pod/sample-pod-overratio created
[root@master1 limitrange]# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
new-pod 1/1 Running 0 45m 10.244.1.22 worker1 <none> <none>
sample-pod 1/1 Running 0 55m 10.244.2.20 worker2 <none> <none>
sample-pod-limitrange 1/1 Running 0 15m 10.244.1.23 worker1 <none> <none>
sample-pod-overratio 0/1 Pending 0 71s <none> <none> <none> <none>
-> ๋ฆฌ๋ฐ๋ ์ธ์ง์ ๋ง๊ฒ ํด์ฃผ๋ ์์ฑ ์๋ฃ. ํ์ง๋ง ํ๋ฉ๊ฑธ๋ฆผ.
apiVersion: v1
kind: Pod
metadata:
name: sample-pod-overratio
spec:
containers:
- name: nginx-container
image: nginx:1.16
resources:
requests:
cpu: 125m
limits:
cpu: 250m
[root@master1 limitrange]# kubectl apply -f sample-pod-overratio.yaml
pod/sample-pod-overratio created
[root@master1 limitrange]# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
new-pod 1/1 Running 0 47m 10.244.1.22 worker1 <none> <none>
sample-pod 1/1 Running 0 57m 10.244.2.20 worker2 <none> <none>
sample-pod-limitrange 1/1 Running 0 17m 10.244.1.23 worker1 <none> <none>
sample-pod-overratio 1/1 Running 0 4s 10.244.2.23 worker2 <none> <none>
-> cpu์ค์ฌ์ ์๋ฃ!
[root@master1 limitrange]# kubectl delete pod,deploy --all
[root@master1 ~]# mkdir schedule && cd $_
# vi pod-schedule.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-schedule-metadata
labels:
app: pod-schedule-labels
spec:
containers:
- name: pod-schedule-containers
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: pod-schedule-service
spec:
type: NodePort
selector:
app: pod-schedule-labels
ports:
- protocol: TCP
port: 80
targetPort: 80
[root@master1 schedule]# kubectl apply -f pod-schedule.yaml
pod/pod-schedule-metadata created
service/pod-schedule-service create
[root@master1 schedule]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/pod-schedule-metadata 1/1 Running 0 29s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/pod-schedule-service NodePort 10.108.76.214 <none> 80:30953
[root@master1 schedule]# curl 10.108.76.214
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
# vi pod-nodename.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-nodename-metadata
labels:
app: pod-nodename-labels
spec:
containers:
- name: pod-nodename-containers
image: nginx
ports:
- containerPort: 80
nodeName: worker2
---
apiVersion: v1
kind: Service
metadata:
name: pod-nodename-service
spec:
type: NodePort
selector:
app: pod-nodename-labels
ports:
- protocol: TCP
port: 80
targetPort: 80
[root@master1 schedule]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ad-hoc1 1/1 Running 0 13m 10.244.1.25 worker1 <none> <none>
pod-nodename-metadata 1/1 Running 0 32s 10.244.2.25 worker2 <none> <none>
pod-schedule-metadata 1/1 Running 0 17m 10.244.2.24 worker2 <none> <none>
# kubectl label nodes worker1 tier=dev
# kubectl get nodes --show-labels
# vi pod-nodeselector.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-nodeselector-metadata
labels:
app: pod-nodeselector-labels
spec:
containers:
- name: pod-nodeselector-containers
image: nginx
ports:
- containerPort: 80
nodeSelector:
tier: dev
---
apiVersion: v1
kind: Service
metadata:
name: pod-nodeselector-service
spec:
type: NodePort
selector:
app: pod-nodeselector-labels
ports:
- protocol: TCP
port: 80
targetPort: 80
# kubectl label nodes worker1 tier-
# kubectl get nodes --show-labels
[root@master1 schedule]# kubectl label node worker1 tier-
-> ๋ผ๋ฒจ์ง์ฐ๊ธฐ
[root@master1 schedule]# kubectl get nodes --show-labels
# kubectl taint node worker1 tier=dev:NoSchedule
# kubectl describe nodes worker1
->ํ๋ค๊ฐ ์์ ๋!
๐โ๏ธโ๏ธ๐ขโญ๏ธ๐
# kubectl create secret generic mj030kk --from-file=.dockerconfigjson=/root/.docker/config.json --type=kubernetes.io/dockerconfigjson
# kubectl patch -n default serviceaccount/default -p '{"imagePullSecrets":[{"name": "mj030kk"}]}'
# kubectl describe serviceaccount default -n default
docker๋ก๊ทธ์ธ์ ์ด์ด์ ์ฟ ๋ฒ๋คํฐ์ค์์๋ ํด์ฃผ์ด์ผ ํจ.
namespace๋ฐ๋ผ๊ฐ๋ฏ๋ก namespace ๋ฐ๋๋ฉด ๋ฐ๋ namespace ๋ฃ์ด์๋ ์งํํด์ฃผ์ด์ผ ํจ.
# kubectl patch -n my-ns serviceaccount/default -p '{"imagePullSecrets":[{"name": "mj030kk"}]}'
[root@master1 configmap]# watch kubectl get all
์ํํ์ธ ์ ๋ฐ์ดํธ ํ๋ฉด์ ๋ณผ ์ ์๊ฒ ํด์ค.