-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
185 lines (105 loc) · 3.8 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#This is a demo.
#create a demo
#remove a env
conda remove --name=demo --all
#create demo env
conda create -n demo
conda activate demo
#install packages
conda install pip
conda install flask
conda install -c conda-forge uwsgi
#run flask by uwsgi
uwsgi --http 127.0.0.1:3031 --wsgi-file main.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
#create requirements.txt
conda list -e > requirements.txt
#pip freeze > requirements.txt
################################################
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
#To export environment file
activate <environment-name>
conda env export > <environment-name>.yml
#For other person to use the environment
conda env create -f <environment-name>.yml
##############################################
#create Dockerfile
#when flask with built-in wsgi server flask
app.run() not work
app.run(host='0.0.0.0') # works! run app.run(host='0.0.0.0') make the server publicly available.
#when use uwsgi as wsgi server
in the .ini,
http = 0.0.0.0
#build image
docker build -t johnzhu999/demo .
#run to make sure it work
docker run -d --name demo -p 4041:3031 johnzhu999/demo
access http://127.0.0.1:4041
returns "Hello from Python!" works!
#push to docker hub
login to docker hub
create repo demo
in local machine
docker login
docker push johnzhu999/demo
#deploy to minikube
#create a deployment
kubectl create deployment demo --image=johnzhu999/demo
#expose port
kubectl expose deployment demo --type=LoadBalancer --port=5000 #5000 is the port that docker container is listening to. it is decided by demo.ini or simply decided by app.run(host='0.0.0.0', port='5000')
#batch deploy docker
inside deplyment.yaml
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: NodePort
containers:
- name: demo
image: johnzhu999/demo
imagePullPolicy: Never
ports:
- containerPort: 5000
kubectl apply -f deployment.yaml
#test if loadBalancer work
#
kubectl apply -f deployment.loadbalancer.yaml
works!
#use asf jenkins and rancher
create a view Data Services
New Item
job name: cicd-demo
type: pipeline
Pipeline script from SCM
SCM git
Repository URL: https://github.com/cirrusasf/cicd_demo.git
credentials: jenkins
branch specifer: */master
problem:
docker push <VIC_Appliance_FQDN_IP>/default-project/some-image-name:latest
The push refers to repository [<VIC_Appliance_FQDN_IP>/default-project/some-image-name]
An image does not exist locally with the tag: <VIC_Appliance_FQDN_IP>/default-roject/some-image-name
Cause
The container image needs to be tag locally for the new registry before it can be pushed.
Resolution
To resolve this issue we must Tag the image using the "docker tag" command.
For example:
docker tag some-image-name:latest <VIC_Appliance_FQDN_IP>/default-project/some-image-name:latest
#rancher
create project data_services
create namespace "cicd-demo" in project "data_services"
#kubectl check rancher
#copy content of the kubeconfig from rancher to local host ~/.kube/config
kubectl get -n cicd-demo pod
#in order for dockerized api work in kubernets, you need define the port and host='0.0.0.0' in app
if __name__ == "__main__":
app.run(port=8080, host='0.0.0.0')
if you do not define port, it will not work.
we use uwsgi as wsgi server to communicate with flask, in the *.ini also need define http = 0.0.0.0:8080
That is to say we must define the same port and host in the two place.
In k8s.yaml, also need define the same port (8080) as it defined in app.
service port 8080
containerPort 8080