- context 매번 변경 확인
kubectl config use-context k8s
- etcd 위치 및 host Path 수정하여 적용
/etc/kubernetes/manifests/etcd.yaml
...
- hostPath:
path: /var/lib/etcd-new
type: DirectoryOrCreate
name: etcd-data
...
- static POD 폴더의 위치 확인 yaml 파일 및 /etc/kubernetes/manifests 에 존재
/var/lib/kubelet/config.yaml
- dry-run=client 및 -o yaml
$ kubectl get pods eshop-cart-app -o yaml > eshop.yaml
$ kubectl run lab004 --image=nginx --dry-run=client -o yaml > multi.yaml
- scale 명령
- rolling update 명령
kubectl set image deployment nginx-app nginx=nginx:1.11.13-alpine --record
kubectl rollout history deployment nginx-app # 내역 확인
kubectl rollout undo deployment nginx-app # Rollback 하기
- 라벨 확인
$ kubectl get nodes -L disktype
apiVersion: v1
kind: Pod
metadata:
name: eshop-store
spec:
containers:
- image: nginx
name: eshop-store
nodeSelector: # 노드 실렉터
disktype: ssd
- cordon, drain 등
$ kubectl cordon [노드 명]
$ kubectl uncordon [노드 명]
$ kubectl drain [노드 명]
$ kubectl drain [노드 명] --ignore-daemonsets # 데몬셋 무시
# 예시
$ kubectl drain node1.example.com --ignore-daemonsets --force --delete-emptydir-data
- node 개수 확인
$ kubectl get nodes | grep -i -w ready | wc -l > ./NODE-count
$ kubectl describe nodes | grep -i taints # taints가 있는 노드는 못 쓰니깐 제외
- expose my app
apiVersion: apps/v1 kind: Deployment metadata: labels: app: front-end name: front-end spec: replicas: 2 revisionHistoryLimit: 10 selector: matchLabels: app: front-end template: metadata: labels: app: front-end spec: containers: - image: ghcr.io/shclub/nginx name: http ports: - name: http containerPort: 80 --- apiVersion: v1 kind: Service metadata: labels: app: front-end name: front-end-svc spec: ports: - port: 80 protocol: TCP targetPort: http name: http selector: app: front-end type: NodePort |
- pod log & cpu 사용냥
# pod log
$ kubectl logs custom-app | grep 'file not found' > ./podlog
# cpu 사용량
$ kubectl top po -l name=overloaded-cpu --sort-by=cpu
- init 컨테이너
$ sudo vi /data/workdir/webpod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web-pod
spec:
containers:
- image: busybox:1.28
name: main
command: ['sh','-c','if [ !-f /workdir/data.txt ];then exit 1;else sleep 300;fi']
volumeMounts:
- name: workdir
mountPath: "/workdir"
initContainers:
- name: init
image: busybox:1.28
command: ['sh', '-c', "touch /workdir/data.txt"]
volumeMounts:
- name: workdir
mountPath: "/workdir"
volumes:
- name: workdir
emptyDir: {}
- config map 운영
$ kubectl create configmap web-config --from-literal=connection_string=localhost:80 --from-literal=external_url=cncf.io
apiVersion: v1 kind: Pod metadata: labels: run: web-pod name: web-pod spec: containers: - image: nginx:1.19.8-alpine name: web-pod envFrom: - configMapRef: name: web-config ports: - containerPort: 80 |
쿠버네티스 홈 - https://kubernetes.io/ko/docs/home/
쿠버네티스 kubectl 명령 가이드라인 - https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
etcd - https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/
sidr car or logging - https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent
scale - https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#scale
rolling update - https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment
init container - https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
node port - https://kubernetes.io/docs/concepts/services-networking/service/#nodeport
config map - https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-a-configmap
config map pod - https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data
secret - https://kubernetes.io/docs/concepts/configuration/secret/#use-cases
secret file - https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-files-from-a-pod
secret env - https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables
hostpath - https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
persistant volume - https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volumes
persistant volume claim - https://kubernetes.io/ko/docs/concepts/storage/persistent-volumes/#%ED%8D%BC%EC%8B%9C%EC%8A%A4%ED%84%B4%ED%8A%B8%EB%B3%BC%EB%A5%A8%ED%81%B4%EB%A0%88%EC%9E%84
persistant volume claim woth pod - https://kubernetes.io/ko/docs/concepts/storage/persistent-volumes/#%EB%B3%BC%EB%A5%A8%EC%9C%BC%EB%A1%9C-%ED%81%B4%EB%A0%88%EC%9E%84%ED%95%98%EA%B8%B0
쿠버 업그레이드 - https://v1-21.docs.kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
'클라우드 > 쿠버네티스' 카테고리의 다른 글
[Kubernetes] 14. 쿠버네티스 Node에 Pod 할당하기 (nodeSelector, Affinity, nodeName) (3) | 2023.03.09 |
---|---|
[Kubernetes] 13. 쿠버네티스 사이드카 패턴(Sidecar pattern) 및 실습 (3) | 2023.03.05 |
[Kubernetes] 12. 쿠버네티스 리소스 오브젝트들 및 생성 방법 (0) | 2023.01.05 |
[kubernetes] 쿠버네티스 클러스터 깔끔하게 초기화 및 오류조치 (0) | 2023.01.04 |
[Kubernetes] 11. 쿠버네티스 etcd 백업/복원 (0) | 2022.12.30 |