개요
- 카타코더 Kubernetes - Deploy Containers Using Kubectl
- 카타코더 Kubernetes - Start containers using Kubectl
Launch Cluster
$ minikube start
o minikube v0.34.1 on linux (amd64)
> Configuring local host environment ...
> Creating none VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
- "minikube" IP address is 172.17.0.24
- Configuring Docker as the container runtime ...
- Preparing Kubernetes environment ...
@ Downloading kubeadm v1.13.3
@ Downloading kubelet v1.13.3
- Pulling images required by Kubernetes v1.13.3 ...
- Launching Kubernetes v1.13.3 using kubeadm ...
- Configuring cluster permissions ...
- Verifying component health .....
+ kubectl is now configured to use "minikube"
= Done! Thank you for using minikube!
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 20s v1.13.3
Kubectl Run
$ kubectl run http --image=katacoda/docker-http-server:latest --replicas=1
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/http created
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
http 1/1 1 1 8s
$ kubectl describe deployment http
Name: http
Namespace: default
CreationTimestamp: Sat, 23 Mar 2019 13:41:01 +0000
Labels: run=http
Annotations: deployment.kubernetes.io/revision: 1
Selector: run=http
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: run=http
Containers:
http:
Image: katacoda/docker-http-server:latest
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: http-869876ccb8 (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 16s deployment-controller Scaled up replica set http-869876ccb8 to 1
Kubectl Expose
$ kubectl expose deployment http --external-ip="172.17.0.24" --port=8000 --target-port=80
service/http exposed
$ curl http://172.17.0.24:8000
<h1>This request was processed by host: http-869876ccb8-ngvm2</h1>
Kubectl Run and Expose
$ kubectl run httpexposed --image=katacoda/docker-http-server:latest --replicas=1 --port=80 --hostport=8001
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/httpexposed created
$ curl http://172.17.0.24:8001
<h1>This request was processed by host: httpexposed-798f6fb658-jggn4</h1>
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
http ClusterIP 10.100.128.52 172.17.0.24 8000/TCP 43s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 117s
$ docker ps | grep httpexposed
e5e7eb2b6125 katacoda/docker-http-server "/app" 27 seconds ago Up 26 seconds k8s_httpexposed_httpexposed-798f6fb658-jggn4_default_741ac3b4-4d71-11e9-a2a0-0242ac110018_0
69183eccdd57 k8s.gcr.io/pause:3.1 "/pause" 29 seconds ago Up 27 seconds 0.0.0.0:8001->80/tcp k8s_POD_httpexposed-798f6fb658-jggn4_default_741ac3b4-4d71-11e9-a2a0-0242ac110018_0
Scale Containers
$ kubectl scale --replicas=3 deployment http
deployment.extensions/http scaled
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
http-869876ccb8-2cq6b 1/1 Running 0 7s
http-869876ccb8-ngvm2 1/1 Running 0 2m1s
http-869876ccb8-njgfp 1/1 Running 0 7s
httpexposed-798f6fb658-jggn4 1/1 Running 0 54s
$ kubectl describe svc http
Name: http
Namespace: default
Labels: run=http
Annotations: <none>
Selector: run=http
Type: ClusterIP
IP: 10.100.128.52
External IPs: 172.17.0.24
Port: <unset> 8000/TCP
TargetPort: 80/TCP
Endpoints: 172.18.0.4:80,172.18.0.6:80,172.18.0.7:80
Session Affinity: None
Events: <none>
$ curl http://172.17.0.24:8000
<h1>This request was processed by host: http-869876ccb8-2cq6b</h1>
$ curl http://172.17.0.24:8000
<h1>This request was processed by host: http-869876ccb8-njgfp</h1>
$ curl http://172.17.0.24:8000
<h1>This request was processed by host: http-869876ccb8-2cq6b</h1>
$ curl http://172.17.0.24:8000
<h1>This request was processed by host: http-869876ccb8-ngvm2</h1>