kubectl taint nodes node1 webserver:NoSchedule
kubectl taint nodes node2 mysql=true:NoSchedule
MySQL
容器空
,不然启动MYSQL会失败mkdir /var/lib/mysql
kubectl create secret generic mysql-auth --from-literal=username=root --from-literal=password=root
vi deployment-cicd-mysql.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: cicd-mysql
spec:
replicas: 1
selector:
matchLabels:
app: cicd-mysql
template:
metadata:
labels:
app: cicd-mysql
spec:
tolerations:
- key: "mysql"
operator: "Equal"
value: "true"
effect: "NoSchedule"
containers:
- name: cicd-mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
args:
- "--ignore-db-dir=lost+found"
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-data
mountPath: "/var/lib/mysql"
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-auth
key: password
volumes:
- name: mysql-data
hostPath:
path: /var/lib/mysql
type: Directory
[root@master project]# kubectl apply -f deployment-cicd-mysql.yaml
deployment.apps/cicd-mysql created
//查看容器内的日志 方便查看报错
kubectl get pods
kubectl describe pods cicd-mysql-bcb77c759-bdrd8
kubectl logs cicd-mysql-6cbd4f95-g64hh
vi service-cicd-mysql.yaml
apiVersion: v1
kind: Service
metadata:
name: service-cicd-mysql
spec:
selector:
app: cicd-mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
type: NodePort
让配置文件生效
kubectl apply -f service-cicd-mysql.yaml
连接数据库初始化数据
mysql -h172.31.178.169 -P32636 -uroot -proot
mysql -h118.190.156.138 -P32636 -uroot -proot
create database cicd;
use cicd;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(255) NOT NULL COMMENT '姓名',
`age` int(11) NOT NULL COMMENT '年龄',
`sex` varchar(255) NOT NULL COMMENT '性别;1男 2女',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
#!/bin/bash
time=$(date "+%Y%m%d%H%M%S")
npm install --registry=https://registry.npm.taobao.org
docker build -t 115.28.139.92:8082/cicd-backend:$time .
docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD 115.28.139.92:8082
docker push 115.28.139.92:8082/cicd-backend:$time
vi mysql.config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
data:
host: "service-cicd-mysql"
port: "3306"
database: "cicd"
kubectl apply -f mysql.config.yaml
vi mysql-auth.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysql-auth
stringData:
username: root
password: root
type: Opaque
kubectl apply -f mysql.config.yaml
kubectl create secret docker-registry private-registry \
--docker-username=admin \
--docker-password=admin123 \
--docker-email=admin@example.org \
--docker-server=115.28.139.92:8082
vi cicd-backend.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: cicd-backend
spec:
selector:
matchLabels:
app: cicd-backend
replicas: 1
template:
metadata:
labels:
app: cicd-backend
spec:
imagePullSecrets:
- name: private-registry
containers:
- name: cicd-backend
imagePullPolicy: Always
image: "115.28.139.92:8082/cicd-backend:20210321202052"
ports:
- containerPort: 7001
env:
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: mysql-config
key: host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: mysql-config
key: port
- name: MYSQL_DATABASE
valueFrom:
configMapKeyRef:
name: mysql-config
key: database
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-auth
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-auth
key: password
kubectl apply -f cicd-backend.yaml
apiVersion: v1
kind: Service
metadata:
name: service-cicd-backend
spec:
selector:
app: cicd-backend
ports:
- protocol: TCP
port: 7001
targetPort: 7001
type: NodePort
kubectl apply -f service-cicd-backend.yaml
curl http://172.31.178.169:31300/user/list
yum -y install gcc gcc-c++ kernel-devel
#!/bin/sh -l
time=$(date "+%Y%m%d%H%M%S")
npm install --registry=https://registry.npm.taobao.org
npm run build
docker build -t 115.28.139.92:8082/cicd-frontend:$time .
docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD 115.28.139.92:8082
docker push 115.28.139.92:8082/cicd-frontend:$time
vi cicd-frontend.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: cicd-frontend
spec:
selector:
matchLabels:
app: cicd-frontend
replicas: 1
template:
metadata:
labels:
app: cicd-frontend
spec:
imagePullSecrets:
- name: private-registry
containers:
- name: cicd-frontend
image: 115.28.139.92:8082/cicd-frontend:20210321204724
kubectl apply -f cicd-frontend.yaml
vi service-cicd-frontend.yaml
apiVersion: v1
kind: Service
metadata:
name: service-cicd-frontend
spec:
selector:
app: cicd-frontend
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort
kubectl apply -f service-cicd-frontend.yaml
kubectl get svc
http://118.190.156.138:31753/
~/.kube/config
拷贝到Content中cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl
k8s-config
=>Target输入k8s-config.yaml
kubectl set image
命令快速设置镜像地址版本#!/bin/bash
time=$(date "+%Y%m%d%H%M%S")
npm install --registry=https://registry.npm.taobao.org
docker build -t 115.28.139.92:8082/cicd-backend:$time .
docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD 115.28.139.92:8082
docker push 115.28.139.92:8082/cicd-backend:$time
+kubectl --kubeconfig=k8s-config.yaml set image deployment/cicd-backend cicd-backend=115.28.139.92:8082/cicd-backend:$time
deployment.apps/cicd-backend image updated
表示更新成功
webhook URL
地址webhookURL
和WebHook 密码
kubectl delete pod cicd-mysql-84795bc9d7-fpjmp --force --grace-period=0