首先,准备三台虚拟机,一台master,两台node
环境说明:
- Ubuntu 20.04
- master 192.168.5.112
- node 192.168.5.113,192.168.5.114
WARNING
必须修改主机名
在master机器上运行如下命令
curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - --docker
# 安装状态
kubectl get all -n kube-system
token地址/var/lib/rancher/k3s/server/node-token
token:K10ab5ba1d423c4d2af65b0fc7148d9a2642c9b143af8864166c3758d3b3f69ed45::server:76d0e237dc24a5f973ffdc62f1156841
节点上运行如下命令
curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://192.168.5.112:6443 K3S_TOKEN=K10ab5ba1d423c4d2af65b0fc7148d9a2642c9b143af8864166c3758d3b3f69ed45::server:76d0e237dc24a5f973ffdc62f1156841 sh -s - --docker
完成后在master运行kubectl get node
查看节点是否已经接入
配置数据库
- mysql-deployment.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql-rc
labels:
name: mysql-rc
spec:
replicas: 1
selector:
name: mysql-pod
template:
metadata:
labels:
name: mysql-pod
spec:
containers:
- name: mysql
image: mysql
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
- mysql-service.yml
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
labels:
name: mysql-svc
spec:
type: NodePort
ports:
- port: 3306
protocol: TCP
targetPort: 3306
name: http
nodePort: 30306
selector:
name: mysql-pod
执行以下命令
# 创建应用
kubectl create -f mysql-deployment.yaml
kubectl create -f mysql-service.yml
# 查看pod
kubectl get pod
链接数据库 192.168.5.112:30306/root@root