Rancher 2.7.0 application
Zero, prerequisite
0.1 Configure kernel routing and forwarding
# vim /etc/sysctl.conf
# cat /etc/sysctl.conf
...
net.ipv4.ip_forward=1
# sysctl -p
net.ipv4.ip_forward = 1
0.2 docker-ce installation
Install docker-ce on all hosts
# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum -y install docker-ce
# systemctl enable --now docker
0.3 rancher deployment
# mkdir -p /opt/data/rancher_data
# docker run -d --privileged -p 80:80 -p 443:443 -v /opt/data/rancher_data:/var/lib/rancher --restart=always --name rancher-2-7-0 rancher/rancher:v2.7.0
1. Rancher initial configuration
2. Create a cluster
Import an existing cluster. The cluster version imported this time is k8s 1.25.2.
Select Universal Import to any kubernetes cluster
Add a name to the imported cluster
Add labels to imported clusters
Register the existing cluster to rancher
After copying, execute relevant commands on the master node in the k8s cluster
[root@k8s-master01 ~]# curl --insecure -sfL https://192.168.10.163/v3/import/pg977t2z59g872brkj75qmxtkgkz8x5lrwwpdhkprvmcjhhr7tp6wm_c-m-p7wrqk4w.yaml | kubectl apply -f -
After execution, check whether 4 namespaces are added
[root@k8s-master01 ~]# kubectl get ns
NAME STATUS AGE
calico-apiserver Active 36h
calico-system Active 36h
cattle-fleet-system Active 60s 新添加
cattle-impersonation-system Active 77s 新添加
cattle-system Active 81s 新添加
default Active 36h
kube-node-lease Active 36h
kube-public Active 36h
kube-system Active 36h
local Active 27s 新添加
tigera-operator Active 36h
After all executions are completed, you can find that all k8s cluster nodes are registered to rancher.
3. Application release
Select the cluster where the application is published
3.1 Deploy Nginx application
Before publishing the application, create a project/namespace
After the project/namespace is created, choose to create a workload (type Deployments)
Specify the namespace, application name, and number of copies for application publishing
Specify pod label
Specify the image and container type used by the application (standard container)
Add a port for application publishing, that is, create a corresponding service
After all the above configurations are completed, click Create
Observe the created application
Access created applications on a physical machine
3.2 Deploy MySQL application
View existing storage classes in k8s cluster
Persistent dynamic storage classes need to be prepared in advance
[root@k8s-master01 ~]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-client (default) fuseim.pri/ifs Delete Immediate false 15h
View in rancher ui interface
Before publishing mysql, create a project/namespace
Create PVC
Create service
Be sure to pay attention to this selector. Create it now. When you create the MySQL application, its Pod label must be consistent with this.
Check the created SVC
[root@k8s-master01 ~]# kubectl get svc -n mydata1
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysqldata1 ClusterIP None <none> 3306/TCP 49s
Parse the IP address corresponding to SVC
Since Headless SVC is used, SVC does not assign ClusterIP, so there is no result.
[root@k8s-master01 ~]# dig -t a mysqldata1.mydata1.svc.cluster.local @10.96.0.10
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> -t a mysqldata1.mydata1.svc.cluster.local @10.96.0.10
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 18405
;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;mysqldata1.mydata1.svc.cluster.local. IN A
;; AUTHORITY SECTION:
cluster.local. 30 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1664333089 7200 1800 86400 30
;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: 三 9月 28 10:47:03 CST 2022
;; MSG SIZE rcvd: 158
Create a Statefulset type application
Select and fill in the corresponding name. The service name is a service created in advance.
Select MySQL container image
Add environment variables
Set the MySQL administrator password through environment variables and add it to the MySQL database
The Pod label must be consistent with the label used by the selector in the created SVC
Since MySQL needs to store data persistently, it needs to select a storage. This time, the PVC created earlier is used.
Mount the PVC created previously to the /var/lib/mysql directory in the MySQL container
Observe application releases
Execute the command to observe whether the application is available
3.3 Deploy WordPress application
Create project/namespace
Observe namespace creation status
[root@k8s-master01 ~]# kubectl get ns
NAME STATUS AGE
calico-apiserver Active 37h
calico-system Active 37h
cattle-fleet-system Active 59m
cattle-impersonation-system Active 59m
cattle-system Active 59m
default Active 37h
kube-node-lease Active 37h
kube-public Active 37h
kube-system Active 37h
local Active 58m
mydata1 Active 34m
nginxweb Active 50m
tigera-operator Active 37h
webpp1 Active 34s 新添加命名空间
Publish the application corresponding to the Deployment
Select Deployment Controller Type
Add the port used by the application. This time, use the node port to publish it.
Configure the environment variables required by the application and connect to the database through environment variables
Parse database domain name for environment variable definition
[root@k8s-master01 ~]# dig -t a mysqldata1-0.mysqldata1.mydata1.svc.cluster.local. @10.96.0.10
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> -t a mysqldata1-0.mysqldata1.mydata1.svc.cluster.local. @10.96.0.10
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38690
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;mysqldata1-0.mysqldata1.mydata1.svc.cluster.local. IN A
;; ANSWER SECTION:
mysqldata1-0.mysqldata1.mydata1.svc.cluster.local. 30 IN A 10.224.69.203 解析出来Pod IP地址
;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: 三 9月 28 11:32:07 CST 2022
;; MSG SIZE rcvd: 143
Observe application creation
Access published applications on physical machines