Ubuntu 18.04
Sponsored Link

Kubernetes : Minikube : Deploy Pod2018/10/22

 
[1] Create or Delete Pods.
# run 2 [test-nginx] pods

root@dlp:~#
kubectl create deployment test-nginx --image=nginx

deployment.apps/test-nginx created
root@dlp:~#
kubectl get pods

NAME                          READY   STATUS    RESTARTS   AGE
test-nginx-6dbb5ccbb6-ghxhm   1/1     Running   0          10s

# show environment variable for [test-nginx] pod

root@dlp:~#
kubectl exec test-nginx-6dbb5ccbb6-ghxhm env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=test-nginx-6dbb5ccbb6-ghxhm
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
NGINX_VERSION=1.15.5-1~stretch
NJS_VERSION=1.15.5.0.2.4-1~stretch
HOME=/root

# shell access to [test-nginx] pod

root@dlp:~#
kubectl exec -it test-nginx-6dbb5ccbb6-ghxhm bash
root@test-nginx-6dbb5ccbb6-ghxhm:/#
hostname

test-nginx-6dbb5ccbb6-ghxhm
root@test-nginx-6dbb5ccbb6-ghxhm:/#
exit
# show logs of [test-nginx] pod

root@dlp:~#
kubectl logs test-nginx-6dbb5ccbb6-ghxhm

127.0.0.1 - - [22/Oct/2018:04:53:47 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.52.1" "-"

# scale out pods

root@dlp:~#
kubectl scale deployment test-nginx --replicas=3

deployment.extensions/test-nginx scaled
root@dlp:~#
kubectl get pods

NAME                          READY   STATUS    RESTARTS   AGE
test-nginx-6dbb5ccbb6-ghxhm   1/1     Running   0          4m
test-nginx-6dbb5ccbb6-j4z2p   1/1     Running   0          11s
test-nginx-6dbb5ccbb6-n54g4   1/1     Running   0          11s

# set service

root@dlp:~#
kubectl expose deployment test-nginx --type="NodePort" --port 80

service "test-nginx" exposed
root@dlp:~#
kubectl get services test-nginx

NAME         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
test-nginx   NodePort   10.96.215.196   <none>        80:31051/TCP   10s

root@dlp:~#
minikube service test-nginx --url

http://192.168.39.30:31051
root@dlp:~#
curl http://192.168.39.30:31051

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
.....
.....
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# delete service

root@dlp:~#
kubectl delete services test-nginx

service "test-nginx" deleted
# delete pods

root@dlp:~#
kubectl delete deployment test-nginx

deployment.extensions "test-nginx" deleted
Matched Content