企业为什么要使用Docker?它到底好在哪里?
容器、Docker与Kubernetes
Docker宣布拥抱k8s,k8s将一统天下?
Minikube:轻松创建单机版 Kubernetes 集群
minikube的使用
安装好minikube, 并确认是否已启动
$ minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100
postgresql
数据库使用官方镜像
$ kubectl run postgresql --image=postgres --env="POSTGRES_PASSWORD=password" --port=5432
deployment "postgresql" created
创建成功后可以查看对应的Deployment和Pod状态
$ kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
postgresql 1 1 1 1 27m
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
postgresql-7877b54d49-hww4w 1/1 Running 0 18m
如果想从外部访问数据库, 可以使用Service暴露这个Pod
$ kubectl expose deployment postgresql --type=LoadBalancer
service "postgresql" exposed
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 49m
postgresql LoadBalancer 10.111.208.150 <pending> 5432:32131/TCP 17m
$ psql -h 192.168.99.100 -p 32131 -U postgres
Password for user postgres:
psql (10.1, server 10.3 (Debian 10.3-1.pgdg90+1))
Type "help" for help.
postgres-# \q
$
删除Service,不再暴露Pod
$ kubectl delete services postgresql
django
构建镜像,为了让构建的镜像不经上传能直接使用.先使用eval $(minikube docker-env)
命令
$ git clone https://github.com/waaaaaaaagh/myblog
$ docker build -t myblog:v1 myblog/django_example/
构建完毕. 创建Deployment和Service
$ kubectl run app --image=myblog:v1 --port=8000
deployment "app" created
$ kubectl expose deployment app --type=LoadBalancer
service "app" exposed
测试的时候却不能访问
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
app LoadBalancer 10.99.200.192 <pending> 8000:30376/TCP 17m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2h
$ curl http://192.168.99.100:30376
curl: (7) Failed to connect to 192.168.99.100 port 30376: Connection refused
发现是镜像的原因. 修改镜像后重新构建镜像为myblog:v2
, 然后更新Deployment
$ kubectl set image deployment/app app=myblog:v2
deployment "app" image updated
稍等片刻可以使用如下命令打开app
$ minikube service app
网友评论