Note: K8S stand-alone installation may encounter many pits, most of the current online tutorials are no longer applicable to the latest version. After stepping on the pit, share with you the method
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install -y etcd kubernetes
Configuration modification reference: https://lihaoquan.me/2017/2/25/create-kubernetes-single-node-mode.html
systemctl start etcd
systemctl start docker
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
systemctl start kubelet.service
systemctl start kube-proxy.service
If you encounter an error, use journalctl -xe to view the error message. You may encounter problems such as setting up a firewall and setting up a proxy.
journalctl -xe
docker pull mysql:5.7
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas:1
selector:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:- name: mysql
image: mysql:5.7
ports:- containerPort:3306
env:- name: MYSQL_ROOT_PASSWORD
value:"123456"
kubectl create -f mysql-rc.yaml
View the specific startup situation of mysql, it will also contain error messages
kubectl describe pod mysql
image.png
wget [http://mirror.centos.org/centos/7/os/x86\_64/Packages/python-rhsm-certificates-1.19.10-1.el7\_4.x86\_64.rpm](http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm)
rpm2cpio python-rhsm-certificates-1.19.10-1.el7\_4.x86\_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
# The rpm2cpio command is used to convert the rpm software package to a file in cpio format. The cpio command is mainly a tool program used to create or restore a backup file. The cpio command can copy files to or from an archive package.
Delete and regenerate mysql rc
kubectl delete-f mysql-rc.yaml
kubectl get pods
kubectl create -f mysql-rc.yaml
image.png
kubectl describe pod mysql
image.png
kubectl get pods
image.png
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:- port:3306
selector:
app: mysql
kubectl create -f mysql-svc.yaml
image.png
docker pull kubeguide/tomcat-app:v1
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas:5
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:- name: myweb
image: docker.io/kubeguide/tomcat-app:v1
ports:- containerPort:8080
env:- name: MYSQL_SERVICE_HOST
value:"10.254.65.209" #<===The mysql address here needs to fill in the mysql address of the service, execute kubectl get svc to view
- name: MYSQL_SERVICE_PORT
value:"3306"
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:- port:8080
nodePort:30001 #External port mapping
selector:
app: myweb
kubectl create -f myweb-rc.yaml
kubectl create -f myweb-svc.yaml
image.png
Visit: http://127.0.0.1:30001/demo/index.jsp to operate
image.png
You can enter the container to view the data already in mysql
image.png
Recommended Posts