K8S: (1) A preliminary study on CentOS stand-alone deployment

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

1. Environmental preparation###

Install VirtualBox:

Download CentOS 7: http://mirrors.163.com/centos/7.7.1908/isos/x86_64/CentOS-7-x86_64-DVD-1908.torrent

Install CentOS 7: If the machine supports it, it is recommended to choose a graphical interface for easy use

Modify software source####

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

Two, install k8s to modify the configuration###

Install k8s, etcd, docker

yum install -y etcd kubernetes

Configuration modification reference: https://lihaoquan.me/2017/2/25/create-kubernetes-single-node-mode.html

Start the following services:

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

Three, pull the boot image

Install mysql

docker pull mysql:5.7

Create the file: mysql-rc.yaml

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 command manual: https://hardocs.com/d/kubernetes/136-Command%20Reference.html

kubectl create -f mysql-rc.yaml

Use mysql 5.7, pull mysql directly will pull to mysql 8 version, old JDBC may not be compatible

View the specific startup situation of mysql, it will also contain error messages

kubectl describe pod mysql

image.png

Download and install the certificate####

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

Create file: mysql-svc.yaml

apiVersion: v1
kind: Service
metadata: 
 name: mysql
spec:
 ports:- port:3306
 selector:
 app: mysql
kubectl create -f mysql-svc.yaml

image.png

Pull and run the demo image of tomcat####

docker pull kubeguide/tomcat-app:v1

Create file: myweb-rc.yaml

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"

Create file: myweb-svc.yaml

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

Fourth, external access and view data

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

K8S: (1) A preliminary study on CentOS stand-alone deployment
A preliminary study on centos mysql-configuration, basic operations and problems
Build k8s1.9.9 on centos7
Deployment of graphite on centos7
k8s practice (1): Centos 7.6 deployment k8s (v1.14.2) cluster
Concise summary of Ceph deployment on Centos7
How to build a LAMP environment on centos7.2
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
CentOS deployment Harbor
Set up a CentOS network with Virtualbox on MacOS
Use Rancher to build a K8s cluster under CentOS7
Install KVM on CentOS 7 and create a virtual machine
Rapid deployment of Kubernetes (k8s) cluster in CentOS7 environment