curl -LO https://storage.googleapis.com/minikube/releases/v1.22.0/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube --help
curl -LO https://dl.k8s.io/release/v1.22.1/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl --help
$ minikube start --driver=docker
😄 minikube v1.22.0 on Ubuntu 20.04
✨ Using the docker driver based on user configuration
💣 Exiting due to PROVIDER_DOCKER_NEWGRP: "docker version --format -" exit status 1: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
💡 Suggestion: Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker'
📘 Documentation: https://docs.docker.com/engine/install/linux-postinstall/
1-2. 트러블 슈팅1
sudo usermod -aG docker $USER
newgrp docker
minikube start --driver=docker
$ sudo usermod -aG docker $USER
rp docker
$ newgrp docker
$ minikube start --driver=docker
😄 minikube v1.22.0 on Ubuntu 20.04
✨ Using the docker driver based on user configuration
🎉 minikube 1.32.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.32.0
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.21.2 preload ...
> preloaded-images-k8s-v11-v1...: 502.14 MiB / 502.14 MiB 100.00% 29.21 Mi
> gcr.io/k8s-minikube/kicbase...: 361.08 MiB / 361.09 MiB 100.00% 15.39 Mi
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
🐳 Preparing Kubernetes v1.21.2 on Docker 20.10.7 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
1-3. 트러블슈팅2. 컴퓨터 사양을 늘려보자
$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
2-1. kubectl 시스템의 구성 확인
$ kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-558bd4d5db-d4ff9 1/1 Running 1 41m
etcd-minikube 1/1 Running 1 41m
kube-apiserver-minikube 1/1 Running 1 41m
kube-controller-manager-minikube 1/1 Running 1 41m
kube-proxy-d4vk9 1/1 Running 1 41m
kube-scheduler-minikube 1/1 Running 1 41m
storage-provisioner 1/1 Running 2 41m
minikube delete
apiVersion: v1 # kubernetes resource 의 API Version
kind: Pod # kubernetes resource name
metadata: # 메타데이터 : name, namespace, labels, annotations 등을 포함
name: counter
spec: # 메인 파트 : resource 의 desired state 를 명시
containers:
- name: count # container 의 이름
image: busybox # container 의 image
args: [/bin/sh, -c, 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done'] # 해당 image 의 entrypoint 의 args 로 입력하고 싶은 부분
$ kubectl apply -f pod.yaml
pod/counter created
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
counter 1/1 Running 0 6m56s
$ kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default counter 1/1 Running 0 10m
kube-system coredns-558bd4d5db-d4ff9 1/1 Running 1 85m
kube-system etcd-minikube 1/1 Running 1 86m
kube-system kube-apiserver-minikube 1/1 Running 1 86m
kube-system kube-controller-manager-minikube 1/1 Running 1 86m
kube-system kube-proxy-d4vk9 1/1 Running 1 85m
kube-system kube-scheduler-minikube 1/1 Running 1 86m
kube-system storage-provisioner 1/1 Running 2 86m
$ kubectl get pod counter
NAME READY STATUS RESTARTS AGE
counter 1/1 Running 0 11m
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
counter 1/1 Running 0 13m 172.17.0.3 minikube <none> <none>
$ cat a.yaml
apiVersion: v1
items:
- apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"counter","namespace":"default"},"spec":{"containers":[{"args":["/bin/sh","-c","i=0; while true; do echo \"$i: $(date)\"; i=$((i+1)); sleep 1; done"],"image":"busybox","name":"count"}]}}
$ kubectl get pod -w
NAME READY STATUS RESTARTS AGE
counter 1/1 Running 0 135m
$ kubectl logs counter
0: Fri Jan 12 02:34:36 UTC 2024
1: Fri Jan 12 02:34:37 UTC 2024
2: Fri Jan 12 02:34:38 UTC 2024
3: Fri Jan 12 02:34:39 UTC 2024
4: Fri Jan 12 02:34:40 UTC 2024
5: Fri Jan 12 02:34:41 UTC 2024
6: Fri Jan 12 02:34:42 UTC 2024
kubectl exec -it counter /bin/bash
$ kubectl delete pod counter
pod "counter" deleted
apiVersion: apps/v1 # kubernetes resource 의 API Version
kind: Deployment # kubernetes resource name
metadata: # 메타데이터 : name, namespace, labels, annotations 등을 포함
name: nginx-deployment
labels:
app: nginx
spec: # 메인 파트 : resource 의 desired state 를 명시
replicas: 3 # 동일한 template 의 pod 을 3 개 복제본으로 생성합니다.
selector:
matchLabels:
app: nginx
template: # Pod 의 template 을 의미합니다.
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx # container 의 이름
image: nginx:1.14.2 # container 의 image
ports:
- containerPort: 80 # container 의 내부 Port
replicas : 3
: pod의 갯수를 3으로 지정하겠다. 복제본 3개가 생성되어서 가용성이 증가함.
kubectl apply -f deployment.yaml
$ kubectl apply -f deployment.yaml
deployment.apps/nginx-deployment created
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 2m39s
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-66b6c48dd5-45xkd 1/1 Running 0 5m19s
nginx-deployment-66b6c48dd5-5zvll 1/1 Running 0 5m19s
nginx-deployment-66b6c48dd5-s8mtq 1/1 Running 0 5m19s
$ kubectl delete pod nginx-deployment-66b6c48dd5-s8mtq
pod "nginx-deployment-66b6c48dd5-s8mtq" deleted
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-66b6c48dd5-45xkd 1/1 Running 0 8m16s
nginx-deployment-66b6c48dd5-5zvll 1/1 Running 0 8m16s
nginx-deployment-66b6c48dd5-btwqc 1/1 Running 0 22s
$ kubectl scale deployment/nginx-deployment --replicas=5
deployment.apps/nginx-deployment scaled
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-66b6c48dd5-45xkd 1/1 Running 0 11m
nginx-deployment-66b6c48dd5-5zvll 1/1 Running 0 11m
nginx-deployment-66b6c48dd5-btwqc 1/1 Running 0 3m57s
nginx-deployment-66b6c48dd5-m76j8 1/1 Running 0 3s
nginx-deployment-66b6c48dd5-n5ffh 1/1 Running 0 3s
$ kubectl delete -f deployment.yaml
deployment.apps "nginx-deployment" deleted
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deployment-66b6c48dd5-8frt4 1/1 Running 0 67s 172.17.0.4 minikube <none> <none>
nginx-deployment-66b6c48dd5-mwrcc 1/1 Running 0 67s 172.17.0.5 minikube <none> <none>
nginx-deployment-66b6c48dd5-xkmwd 1/1 Running 0 67s 172.17.0.3 minikube <none> <none>
$ curl -X GET 172.17.0.4 -vvv
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 172.17.0.4:80...
* TCP_NODELAY set
* connect to 172.17.0.4 port 80 failed: No route to host
* Failed to connect to 172.17.0.4 port 80: No route to host
* Closing connection 0
curl: (7) Failed to connect to 172.17.0.4 port 80: No route to host
$ minikube ssh
docker@minikube:~$
docker@minikube:~$ curl -X GET 172.17.0.4 -vvv
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 172.17.0.4:80...
* TCP_NODELAY set
* Connected to 172.17.0.4 (172.17.0.4) port 80 (#0)
> GET / HTTP/1.1
> Host: 172.17.0.4
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
apiVersion: v1
kind: Service
metadata:
name: my-nginx
labels:
run: my-nginx
spec:
type: NodePort # Service 의 Type 을 명시하는 부분입니다. 자세한 설명은 추후 말씀드리겠습니다.
ports:
- port: 80
protocol: TCP
selector: # 아래 label 을 가진 Pod 을 매핑하는 부분입니다.
app: nginx
$ kubectl apply -f service.yaml
service/my-nginx created
$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h40m
my-nginx NodePort 10.104.175.251 <none> 80:32528/TCP 2m7s