https://github.com/kubernetes-sigs/kubespray
- kubespray를 받을 수 있는 깃허브 주소
https://kubernetes.io/ko/docs/setup/production-environment/tools/kubespray/
- 쿠버스프레이에 대해 설명한 공식 문서
git clone --branch release-2.14 https://github.com/kubernetes-sigs/kubespray.git
cd kubespray
sudo apt install python3-pip
sudo pip3 install -r requirements.txt
ssh-keygen
ssh-copy-id vagrant@192.168.201.11
ssh-copy-id vagrant@192.168.201.21
ssh-copy-id vagrant@192.168.201.22
ssh-copy-id vagrant@192.168.201.23
cp -r inventory/sample inventory/mycluster
-ansidble로 구성되기 때문에 인벤토리의 설정을 구성해야한다. 사전제공된 인벤토리를 자신의 디렉토리를 만들어 복사한다.
vi inventory/mycluster/inventory.ini
[all]
k8s-m1 ansible_host=192.168.201.11 ip=192.168.201.11 ansible_connection=local
k8s-w1 ansible_host=192.168.201.21 ip=192.168.201.21
k8s-w2 ansible_host=192.168.201.22 ip=192.168.201.22
k8s-w3 ansible_host=192.168.201.23 ip=192.168.201.23
[kube-master]
k8s-m1
[etcd]
k8s-m1
[kube-node]
k8s-w1
k8s-w2
k8s-w3
[calico-rr]
[k8s-cluster:children]
kube-master
kube-node
calico-rr
ansible all -i inventory/mycluster/inventory.ini -m ping
ansible-playbook -i inventory/mycluster/inventory.ini cl
uster.yml -b
-ansible playbook을 실행하여 쿠버네티스를 배포한다.
mkdir $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl
exec bash
kubectl run test -it --rm --image=ubuntu
kubectl exec -it web-pod -c httpd1 bash
kubectl run
kubectl create
kubectl get
kubectl get -o wide
kubectl get -o yaml
kubectl describe
kubectl logs (-c)
kubectl port-forward (-c)
kubectl exec (-c)
kubectl delete
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: myapp
image: ghcr.io/c1t1d0s7/go-myweb
ports:
- containerPort: 8080
protocol: TCP
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/labels/
...
metadata:
name: myapp-pod
labels:
app: myapp
env: development
...
kubectl label pod web1 app=httpd
kubectl label pod web1 app=myapp --overwrite
kubectl label pod web1 app='' --overwrite
kubectl label pod web1 app-
kubectl get pods --show-labels
kubectl get pod myapp-pod -o yaml
kubectl describe pod myapp-pod
kubectl get -l <EXPR>
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/annotations/
kubectl annotate pod web1 header=jang
kubectl annotate pod web1 header=kim --overwrite
kubectl annotate pod web1 header-
metadata:
name: myapp-pod
labels:
app: myapp
env: development
annotations:
header: jang
...
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/namespaces/
kubectl -n | --namespace
metadata:
name: myapp-pod
namespace: kube-system
kubectl create namespace quality-assurance
apiVersion: v1
kind: Namespace
metadata:
name: quality-assurance
https://kubernetes.io/ko/docs/concepts/workloads/pods/pod-lifecycle/
https://kubernetes.io/ko/docs/concepts/workloads/controllers/replicationcontroller/
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 3
selector:
app: nginx
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
.spec.replicas: 복제본 개수(기본: 1)
.spec.selector: 파드 레이블 셀렉터
.spec.template: 파드 템플릿
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
파드, 레이블, 셀렉터, 레플리케이션 컨트롤러의 설명은... 너무 어렵다. 혼자서 더 복습해봐야 겠다.