In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to integrate docker in Kubernetes? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
K8s is a container cluster management system, which provides functions such as resource scheduling, balanced disaster recovery, service registration, dynamic capacity expansion and so on.
Introduction to Kubernetes components:
Etcd: stores Kubernetes information, various business container information, etc., and stores flannel network configuration information for coordination among nodes. It's kubernetes's database.
Flannel: for cross-host network communication between multiple containers
Management Interface of kube-apiserver:k8s
Kube-controller-manager: performing Kubernetes services
Kube-scheduler: container startup, migration, expansion and reduction scheduling
Kubelet: the actual operator of the container
Kube-proxy: reverse proxy for container network
Prepare:
1. Turn off centos7's firewall firewalld
$systemctl stop firewalld
$systemctl disable firewalld
two。 Install NTP and make sure it is enabled and running
$yum-y install ntp
$systemctl start ntpd
$systemctl enable ntpd
Configure Kubernetes Master:
Perform the following steps on master
1. Install etcd and Kubernetes through yum:
$yum-y install etcd kubernetes
two。 Configure all addresses in etcd snooping / etc/etcd/etcd.conf:
ETCD_NAME=default
ETCD_DATA_DIR= "/ var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS= "http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS= "http://localhost:2379"
3. Configure the Kubernetes interface service, / etc/kubernetes/apiserver
KUBE_API_ADDRESS= "--address=0.0.0.0"
KUBE_API_PORT= "--port=8080"
KUBELET_PORT= "--kubelet_port=10250"
KUBE_ETCD_SERVERS= "--etcd_servers= http://127.0.0.1:2379"
KUBE_SERVICE_ADDRESSES= "--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL= "--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS= ""
4. Start and enable etcd, kube-apiserver, kube- controllermanager, and kube-scheduler:
$for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do
Systemctl restart $SERVICES
Systemctl enable $SERVICES
Systemctl status $SERVICES
Done
5. Define flannel configuration in etcd
$etcdctl mk / atomic.io/network/config'{"Network": "172.17.0.0max 16"}'
6. Check the status of the node. There is no information because it has not been started yet.
$kubectl get nodes
NAME LABELS STATUS
Configure the Kubernetes Minions node:
The following steps are performed on minion1, minion2, and minion3
1. Install flannel and Kubernetes
$yum-y install flannel kubernetes
two。 Configure the etcd server for the flannel service. The following line in update / etc/sysconfig/flanneld connects to the master server:
FLANNEL_ETCD= "http://192.168.204.30:2379"
3. Configure the main service interface of Kubernetes in / etc/kubernetes/config
KUBE_MASTER= "--master= http://192.168.204.30:8080"
4. Configuration / etc/kubernetes/kubelet
Minion1:
KUBELET_ADDRESS= "--address=0.0.0.0"
KUBELET_PORT= "--port=10250"
# change the hostname to this host's IP address
KUBELET_HOSTNAME= "--hostname_override=192.168.204.31"
KUBELET_API_SERVER= "--api_servers= http://192.168.204.30:8080"
KUBELET_ARGS= ""
Minion2:
KUBELET_ADDRESS= "--address=0.0.0.0"
KUBELET_PORT= "--port=10250"
# change the hostname to this host's IP address
KUBELET_HOSTNAME= "--hostname_override=192.168.204.32"
KUBELET_API_SERVER= "--api_servers= http://192.168.204.30:8080"
KUBELET_ARGS= ""
Minion3:
KUBELET_ADDRESS= "--address=0.0.0.0"
KUBELET_PORT= "--port=10250"
# change the hostname to this host's IP address
KUBELET_HOSTNAME= "--hostname_override=192.168.204.33"
KUBELET_API_SERVER= "--api_servers= http://192.168.204.30:8080"
KUBELET_ARGS= ""
5. Start the kube-proxy, kubelet, docker, and flanneld services:
$for SERVICES in kube-proxy kubelet docker flanneld; do
Systemctl restart $SERVICES
Systemctl enable $SERVICES
Systemctl status $SERVICES
Done
6. Check for docker0 and flannel0 on each minion. Different ranges of IP addresses can be obtained on flannel0
Minion1:
$ip a | grep flannel | grep inet
Inet 172.17.59.0/16 scope global flannel0
Minion2:
$ip a | grep flannel | grep inet
Inet 172.17.19.0/16 scope global flannel0
Minion3:
$ip a | grep flannel | grep inet
Inet 172.17.80.0/16 scope global flannel0
7. Check node status
$kubectl get nodes
NAME STATUS AGE
192.168.204.31 Ready 8m
192.168.204.32 Ready 7m
192.168.204.33 Ready 7m
The Kubernetes cluster is already configured and running. Start configuring pods
Configure pods (Containers)
1. Define a yaml file in Kubernetes master and use the kubectl command to create a pods based on the definition. Create a mysql.yaml file:
$mkdir pods
$cd pods
$vim mysql.yaml
two。 Add the following lines:
ApiVersion: v1
Kind: Pod
Metadata:
Name: mysql
Labels:
Name: mysql
Spec:
Containers:
-resources:
Limits:
Cpu: 1
Image: mysql
Name: mysql
Env:
-name: MYSQL_ROOT_PASSWORD
# change this
Value: yourpassword
Ports:
-containerPort: 3306
Name: mysql
3. Create pod
$kubectl create-f mysql.yaml
4. Verify the creation and operation of pod:
$kubectl get pods
POD IP CONTAINER (S) IMAGE (S) HOST LABELS STATUS CREATED
Mysql 172.17.38.2 mysql mysql 192.168.204.32/192.168.204.32 name=mysql Running 3 hours
Kubernetes created a Docker container in 192.168.204.32. Now you need to create a service that allows other pods to access the mysql database on known ports and hosts.
Create a service
1. There is a MySQL pod in 192.168.204.32, which defines a mysql-service.yaml
ApiVersion: v1
Kind: Service
Metadata:
Labels:
Name: mysql
Name: mysql
Spec:
ExternalIPs:
-192.168.204.32
Ports:
# this port is the port of the service
-port: 3306
# label keys and values that must match in order to receive traffic for this service
Selector:
Name: mysql
two。 Run the service
$kubectl create-f mysql-service.yaml
Report exception: Error from server (BadRequest): error when creating "mysql.yaml": Pod in version "v1" cannot be handled as a Pod: [pos 177]: json: expect char'"'but got char' 1'
3. To view the service, 10.254.x.x is the internal IP address of the Kubernetes defined in / etc/kubernetes/apiserver, so the network ip connected to the outside is defined:
$kubectl get services
NAME LABELS SELECTOR IP PORT (S)
Kubernetes component=apiserver,provider=kubernetes 10.254.0.2 443/TCP
Kubernetes-ro component=apiserver,provider=kubernetes 10.254.0.1 80/TCP
Mysql name=mysql name=mysql 10.254.13.156 3306/TCP
192.168.204.32
4. External connection to the database
$mysql-uroot-p-h292.168.204.32
MySQL [(none)] > show variables like'% version%'
+-- +
| | Variable_name | Value |
+-- +
| | innodb_version | 5.6.24 |
| | protocol_version | 10 | |
| | slave_type_conversions |
| | version | 5.6.24 |
| | version_comment | MySQL Community Server (GPL) |
| | version_compile_machine | x86room64 | |
| | version_compile_os | Linux |
+-- +
7 rows in set (0.01 sec)
This is the answer to the question about how to integrate docker in Kubernetes. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.