$ minikube config set vm-driver virtualbox
$ minikube start```
竟然不是master ,ROLES 是none ,那是什么?
kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready 26h v1.15.2
zhangb
Docker image
Minikube comes with its own docker daemon. Run the following so that we can work with that docker daemon on our machine. 要执行这个:
eval $(minikube docker-env)
We have built 3 apps: auth, gateway, books. People sometimes refer to them as services, however, we will call them apps so as to distinguish the Kubenete Service.
cd python+flask
docker build ./gateway_app -t gateway
docker build ./auth_app -t auth
docker build ./books_app -t books
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask/auth_app master cat Dockerfile
FROM continuumio/miniconda:latest
WORKDIR /home/app
COPY environment.yml ./
RUN conda env create -f environment.yml
RUN echo "source activate microservices" > ~/.bashrc
ENV PATH /opt/conda/envs/microservices/bin:$PATH
COPY *.py ./
COPY run.sh ./
RUN chmod +x run.sh
EXPOSE 8080
ENTRYPOINT ["./run.sh"]
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask/auth_app master cd ..
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master ls
auth_app books_app gateway_app
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker build ./gateway_app -t gateway
Sending build context to Docker daemon 5.632kB
Step 1/11 : FROM continuumio/miniconda:latest
latest: Pulling from continuumio/miniconda
1ab2bdfe9778: Pull complete
2725429bf84b: Pull complete
b662651ecc14: Pull complete
Digest: sha256:b8dab8699fedbfbae102ae6d26d8aae2061e58648829d1942d43ec0cece6c34b
Status: Downloaded newer image for continuumio/miniconda:latest
---> f3ca74752199
Step 2/11 : WORKDIR /home/app
---> Running in 2395aa6a2067
Removing intermediate container 2395aa6a2067
---> 2c610b623946
Step 3/11 : COPY environment.yml ./
---> cfcf2d14d2f7
Step 4/11 : RUN conda env create -f environment.yml
---> Running in 02da27ab800b
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done
==> WARNING: A newer version of conda exists. <==
current version: 4.7.10
latest version: 4.7.11
Please update conda by running
$ conda update -n base -c defaults conda
Downloading and Extracting Packages
six-1.12.0 | 23 KB | ########## | 100%
pysocks-1.7.0 | 31 KB | ########## | 100%
ca-certificates-2019 | 126 KB | ########## | 100%
setuptools-41.0.1 | 506 KB | ########## | 100%
xz-5.2.4 | 283 KB | ########## | 100%
wheel-0.33.4 | 41 KB | ########## | 100%
idna-2.8 | 85 KB | ########## | 100%
urllib3-1.24.2 | 159 KB | ########## | 100%
cryptography-2.7 | 544 KB | ########## | 100%
itsdangerous-1.1.0 | 28 KB | ########## | 100%
python-3.7.4 | 32.1 MB | ########## | 100%
pycparser-2.19 | 171 KB | ########## | 100%
jinja2-2.10.1 | 195 KB | ########## | 100%
certifi-2019.6.16 | 152 KB | ########## | 100%
libgcc-ng-9.1.0 | 5.1 MB | ########## | 100%
markupsafe-1.1.1 | 29 KB | ########## | 100%
asn1crypto-0.24.0 | 156 KB | ########## | 100%
requests-2.22.0 | 90 KB | ########## | 100%
flask-1.1.1 | 73 KB | ########## | 100%
zlib-1.2.11 | 103 KB | ########## | 100%
sqlite-3.29.0 | 1.1 MB | ########## | 100%
_libgcc_mutex-0.1 | 3 KB | ########## | 100%
tk-8.6.8 | 2.8 MB | ########## | 100%
werkzeug-0.15.5 | 256 KB | ########## | 100%
cffi-1.12.3 | 222 KB | ########## | 100%
libffi-3.2.1 | 40 KB | ########## | 100%
ncurses-6.1 | 777 KB | ########## | 100%
click-7.0 | 120 KB | ########## | 100%
pip-19.2.2 | 1.6 MB | ########## | 100%
pyopenssl-19.0.0 | 84 KB | ########## | 100%
libedit-3.1.20181209 | 163 KB | ########## | 100%
libstdcxx-ng-9.1.0 | 3.1 MB | ########## | 100%
gunicorn-19.9.0 | 180 KB | ########## | 100%
readline-7.0 | 324 KB | ########## | 100%
openssl-1.1.1c | 2.5 MB | ########## | 100%
chardet-3.0.4 | 174 KB | ########## | 100%
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use
#
# $ conda activate microservices
#
# To deactivate an active environment, use
#
# $ conda deactivate
Removing intermediate container 02da27ab800b
---> 1640a51d39ad
Step 5/11 : RUN echo "source activate microservices" > ~/.bashrc
---> Running in 80dff2edd6cb
Removing intermediate container 80dff2edd6cb
---> 28aeb0db9a00
Step 6/11 : ENV PATH /opt/conda/envs/microservices/bin:$PATH
---> Running in c0187981cf87
Removing intermediate container c0187981cf87
---> 8e1da9313249
Step 7/11 : COPY *.py ./
---> f553ccc4bece
Step 8/11 : COPY run.sh ./
---> 43a300c87f12
Step 9/11 : RUN chmod +x run.sh
---> Running in f269911f1eb7
Removing intermediate container f269911f1eb7
---> 1a69845fb794
Step 10/11 : EXPOSE 8080
---> Running in e32e5f032047
Removing intermediate container e32e5f032047
---> 0cf2e155121e
Step 11/11 : ENTRYPOINT ["./run.sh"]
---> Running in 4abbf4305c63
Removing intermediate container 4abbf4305c63
---> 86459c7bc4f3
Successfully built 86459c7bc4f3
Successfully tagged gateway:latest
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker build ./auth_app -t auth
Sending build context to Docker daemon 5.12kB
Step 1/11 : FROM continuumio/miniconda:latest
---> f3ca74752199
Step 2/11 : WORKDIR /home/app
---> Using cache
---> 2c610b623946
Step 3/11 : COPY environment.yml ./
---> b5e0f9dabb69
Step 4/11 : RUN conda env create -f environment.yml
---> Running in 68d0e9bfac7c
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done
==> WARNING: A newer version of conda exists. <==
current version: 4.7.10
latest version: 4.7.11
Please update conda by running
$ conda update -n base -c defaults conda
Downloading and Extracting Packages
ca-certificates-2019 | 126 KB | ########## | 100%
setuptools-41.0.1 | 506 KB | ########## | 100%
xz-5.2.4 | 283 KB | ########## | 100%
wheel-0.33.4 | 41 KB | ########## | 100%
itsdangerous-1.1.0 | 28 KB | ########## | 100%
python-3.7.4 | 32.1 MB | ########## | 100%
jinja2-2.10.1 | 195 KB | ########## | 100%
certifi-2019.6.16 | 152 KB | ########## | 100%
libgcc-ng-9.1.0 | 5.1 MB | ########## | 100%
markupsafe-1.1.1 | 29 KB | ########## | 100%
flask-1.1.1 | 73 KB | ########## | 100%
zlib-1.2.11 | 103 KB | ########## | 100%
sqlite-3.29.0 | 1.1 MB | ########## | 100%
_libgcc_mutex-0.1 | 3 KB | ########## | 100%
tk-8.6.8 | 2.8 MB | ########## | 100%
werkzeug-0.15.5 | 256 KB | ########## | 100%
libffi-3.2.1 | 40 KB | ########## | 100%
ncurses-6.1 | 777 KB | ########## | 100%
click-7.0 | 120 KB | ########## | 100%
pip-19.2.2 | 1.6 MB | ########## | 100%
libedit-3.1.20181209 | 163 KB | ########## | 100%
libstdcxx-ng-9.1.0 | 3.1 MB | ########## | 100%
gunicorn-19.9.0 | 180 KB | ########## | 100%
readline-7.0 | 324 KB | ########## | 100%
openssl-1.1.1c | 2.5 MB | ########## | 100%
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use
#
# $ conda activate microservices
#
# To deactivate an active environment, use
#
# $ conda deactivate
Removing intermediate container 68d0e9bfac7c
---> b08cafd04260
Step 5/11 : RUN echo "source activate microservices" > ~/.bashrc
---> Running in 4bb267a53d18
Removing intermediate container 4bb267a53d18
---> 7c6ae3786787
Step 6/11 : ENV PATH /opt/conda/envs/microservices/bin:$PATH
---> Running in 8bee298a71b2
Removing intermediate container 8bee298a71b2
---> 6e9c7a1f27a7
Step 7/11 : COPY *.py ./
---> faaf81dda319
Step 8/11 : COPY run.sh ./
---> 6503d6395b07
Step 9/11 : RUN chmod +x run.sh
---> Running in 913fd5de537b
Removing intermediate container 913fd5de537b
---> bc9953dd0786
Step 10/11 : EXPOSE 8080
---> Running in 287383f47160
Removing intermediate container 287383f47160
---> 915c9195297c
Step 11/11 : ENTRYPOINT ["./run.sh"]
---> Running in a1ce105f07f7
Removing intermediate container a1ce105f07f7
---> 4e6fde89648c
Successfully built 4e6fde89648c
Successfully tagged auth:latest
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker build ./books_app -t books
Sending build context to Docker daemon 5.12kB
Step 1/11 : FROM continuumio/miniconda:latest
---> f3ca74752199
Step 2/11 : WORKDIR /home/app
---> Using cache
---> 2c610b623946
Step 3/11 : COPY environment.yml ./
---> Using cache
---> b5e0f9dabb69
Step 4/11 : RUN conda env create -f environment.yml
---> Using cache
---> b08cafd04260
Step 5/11 : RUN echo "source activate microservices" > ~/.bashrc
---> Using cache
---> 7c6ae3786787
Step 6/11 : ENV PATH /opt/conda/envs/microservices/bin:$PATH
---> Using cache
---> 6e9c7a1f27a7
Step 7/11 : COPY *.py ./
---> 7611124cb205
Step 8/11 : COPY run.sh ./
---> 2090d76d56b6
Step 9/11 : RUN chmod +x run.sh
---> Running in c429091849cb
Removing intermediate container c429091849cb
---> edd7cca103f9
Step 10/11 : EXPOSE 8080
---> Running in 9a2bfa1319ea
Removing intermediate container 9a2bfa1319ea
---> 238817f6fd8d
Step 11/11 : ENTRYPOINT ["./run.sh"]
---> Running in 38a45226b863
Removing intermediate container 38a45226b863
---> 1f3cc817fe1a
Successfully built 1f3cc817fe1a
Successfully tagged books:latest
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}"
REPOSITORY TAG IMAGE ID
books latest 1f3cc817fe1a
auth latest 4e6fde89648c
gateway latest 86459c7bc4f3
continuumio/miniconda latest f3ca74752199
k8s.gcr.io/kube-apiserver v1.15.2 34a53be6c9a7
k8s.gcr.io/kube-scheduler v1.15.2 88fa9cb27bd2
k8s.gcr.io/kube-controller-manager v1.15.2 9f5df470155d
k8s.gcr.io/kube-proxy v1.15.2 167bbf6c9338
k8s.gcr.io/kube-addon-manager v9.0 119701e77cbc
k8s.gcr.io/coredns 1.3.1 eb516548c180
k8s.gcr.io/kubernetes-dashboard-amd64 v1.10.1 f9aed6605b81
k8s.gcr.io/etcd 3.3.10 2c4adeb21b4f
k8s.gcr.io/k8s-dns-sidecar-amd64 1.14.13 4b2e93f0133d
k8s.gcr.io/k8s-dns-kube-dns-amd64 1.14.13 55a3c5209c5e
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64 1.14.13 6dc8ef8287d3
k8s.gcr.io/pause 3.1 da86e6ba6ca1
gcr.io/k8s-minikube/storage-provisioner v1.8.1 4689081edb10
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker run -d -it -p 3000:8080 books
7f20cb9598eb120c3276abba6cc283acf66bc2628cfaa3177e913f968d0840ef
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker ps --format "table {{.Image}}\t{{.Ports}} \t{{.Names}}"
IMAGE PORTS NAMES
books 0.0.0.0:3000->8080/tcp ecstatic_greider
4689081edb10 k8s_storage-provisioner_storage-provisioner_kube-system_a088b991-7f07-4db1-8fe0-6a732666027b_0
k8s.gcr.io/pause:3.1 k8s_POD_storage-provisioner_kube-system_a088b991-7f07-4db1-8fe0-6a732666027b_0
eb516548c180 k8s_coredns_coredns-5c98db65d4-pkkhs_kube-system_7950baed-8c05-4807-b59c-14c3026c30f4_0
eb516548c180 k8s_coredns_coredns-5c98db65d4-8nlmg_kube-system_1a258d36-f5ee-43de-b40d-bc99d6adbd05_0
k8s.gcr.io/pause:3.1 k8s_POD_coredns-5c98db65d4-pkkhs_kube-system_7950baed-8c05-4807-b59c-14c3026c30f4_0
k8s.gcr.io/pause:3.1 k8s_POD_coredns-5c98db65d4-8nlmg_kube-system_1a258d36-f5ee-43de-b40d-bc99d6adbd05_0
167bbf6c9338 k8s_kube-proxy_kube-proxy-82f4m_kube-system_fdbd36cf-5b74-4aaf-8dd7-b01ae15efe0d_0
k8s.gcr.io/pause:3.1 k8s_POD_kube-proxy-82f4m_kube-system_fdbd36cf-5b74-4aaf-8dd7-b01ae15efe0d_0
2c4adeb21b4f k8s_etcd_etcd-minikube_kube-system_89f36d1de777528a3e8b9a2534a41af4_0
88fa9cb27bd2 k8s_kube-scheduler_kube-scheduler-minikube_kube-system_abfcb4f52e957b11256c1f6841d49700_0
9f5df470155d k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_374ab60c7462b3f9c28c5cc2355d6d08_0
34a53be6c9a7 k8s_kube-apiserver_kube-apiserver-minikube_kube-system_8f6b5d95bfe4bcf4cc9c4d8435f0668b_0
119701e77cbc k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_65a31d2b812b11a2035f37c8a742e46f_0
k8s.gcr.io/pause:3.1 k8s_POD_etcd-minikube_kube-system_89f36d1de777528a3e8b9a2534a41af4_0
k8s.gcr.io/pause:3.1 k8s_POD_kube-controller-manager-minikube_kube-system_374ab60c7462b3f9c28c5cc2355d6d08_0
k8s.gcr.io/pause:3.1 k8s_POD_kube-scheduler-minikube_kube-system_abfcb4f52e957b11256c1f6841d49700_0
k8s.gcr.io/pause:3.1 k8s_POD_kube-addon-manager-minikube_kube-system_65a31d2b812b11a2035f37c8a742e46f_0
k8s.gcr.io/pause:3.1 k8s_POD_kube-apiserver-minikube_kube-system_8f6b5d95bfe4bcf4cc9c4d8435f0668b_0
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master
zhangbin@zhangbin-mbp ~/myProjects/k8s/microservices/python+flask master docker exec -it ecstatic_greider /bin/bash
(microservices) root@7f20cb9598eb:/home/app# curl localhost:8080/api/v1/book/1
bash: curl: command not found
(microservices) root@7f20cb9598eb:/home/app# Run in Terminal app:
bash: Run: command not found
(microservices) root@7f20cb9598eb:/home/app# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
bash: curl: command not found
(microservices) root@7f20cb9598eb:/home/app# brew install curl
bash: brew: command not found
(microservices) root@7f20cb9598eb:/home/app#
(microservices) root@7f20cb9598eb:/home/app#
(microservices) root@7f20cb9598eb:/home/app#
(microservices) root@7f20cb9598eb:/home/app# curl
bash: curl: command not found
(microservices) root@7f20cb9598eb:/home/app# man ls
bash: man: command not found
(microservices) root@7f20cb9598eb:/home/app# ls
__pycache__ environment.yml main.py run.sh
(microservices) root@7f20cb9598eb:/home/app# whoami
root
(microservices) root@7f20cb9598eb:/home/app# cat run.sh
#!/bin/sh
exec gunicorn -b :8080 --access-logfile - --error-logfile - main:app
(microservices) root@7f20cb9598eb:/home/app# cat main.py
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/api/v1/book/')
def book(book_id):
return jsonify({
"book_id": book_id,
"title": "An Absolutely Remarkable Thing",
"author": "Hank Green",
"published_date": "2018-12-25"
})
if __name__ == "__main__":
app.run(debug=False)
(microservices) root@7f20cb9598eb:/home/app#
✘ zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚ minikube status
host: Running
kubelet: Running
apiserver: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100
竟然没看到我的三个服务
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}"
REPOSITORY TAG IMAGE ID
这个似乎是来自于一个镜像,内部端口8080?
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
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/hello-minikube created
对外暴露端口还是服务?
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
kubectl expose deployment hello-minikube --type=NodePort
service/hello-minikube exposed
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-64c7df9db-fjbwh 1/1 Running 0 57s
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
curl $(minikube service hello-minikube --url)
CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://192.168.99.100:8080/
SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001
HEADERS RECEIVED:
accept=*/*
host=192.168.99.100:31313
user-agent=curl/7.54.0
BODY:
-no body in request-% zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
eval $(minikube docker-env)
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}"
REPOSITORY TAG IMAGE ID
books latest 1f3cc817fe1a
auth latest 4e6fde89648c
gateway latest 86459c7bc4f3
continuumio/miniconda latest f3ca74752199
k8s.gcr.io/kube-controller-manager v1.15.2 9f5df470155d
k8s.gcr.io/kube-scheduler v1.15.2 88fa9cb27bd2
k8s.gcr.io/kube-proxy v1.15.2 167bbf6c9338
k8s.gcr.io/kube-apiserver v1.15.2 34a53be6c9a7
k8s.gcr.io/kube-addon-manager v9.0 119701e77cbc
k8s.gcr.io/coredns 1.3.1 eb516548c180
k8s.gcr.io/kubernetes-dashboard-amd64 v1.10.1 f9aed6605b81
k8s.gcr.io/etcd 3.3.10 2c4adeb21b4f
k8s.gcr.io/k8s-dns-sidecar-amd64 1.14.13 4b2e93f0133d
k8s.gcr.io/k8s-dns-kube-dns-amd64 1.14.13 55a3c5209c5e
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64 1.14.13 6dc8ef8287d3
k8s.gcr.io/pause 3.1 da86e6ba6ca1
gcr.io/k8s-minikube/storage-provisioner v1.8.1 4689081edb10 这个新来的
k8s.gcr.io/echoserver 1.4 a90209bb39e3 新来的?也是官方的、
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚
✘ zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚ kubectl delete service hello-minikube
service "hello-minikube" deleted
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚ kubectl delete deployment hello-minikube
deployment.extensions "hello-minikube" deleted
zhangbin@zhangbin-mbp ~/myProjects/GRPC/ServiceMesh cross_ios_maint ●✚