记一次kubernetes+docker部署一个pod的全过程
1、首先从vSphere中创建一个基本的CentOS7.2的虚拟机2、创建完成后安装kubernetes和docker2.1关闭防火墙[root@kubernetes-m ~]# systemctl disable firewalldRemoved symlink /etc/systemd/system/dbus-org.fedoraproject.Firewal...
·
1、首先从vSphere中创建一个基本的CentOS7.2的虚拟机
2、创建完成后安装kubernetes和docker
2.1 关闭防火墙
[root@kubernetes-m ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@kubernetes ~]# systemctl stop firewalld
2.2 安装kubernetes(会自动安装docker)
[root@kubernetes-m ~]# yum install -y etcd kubernetes
2.3 按顺序启动服务
[root@kubernetes-m ~]# systemctl start etcd
[root@kubernetes-m ~]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
启动docker时报错了,查看日志
[root@kubernetes-m ~]# journalctl -xe
--
-- Unit docker-cleanup.timer has finished starting up.
--
-- The start-up result is done.
5月 12 18:00:01 kubernetes-m kernel: TECH PREVIEW: Overlay filesystem may not be fully supported.
Please review provided documentation for limitations.
5月 12 18:00:01 kubernetes-m kernel: SELinux: initialized (dev overlay, type overlay), uses xattr
5月 12 18:00:01 kubernetes-m container-storage-setup[21964]: ERROR: XFS filesystem at /var has ftype=0, cannot use overlay backend; consider different driver or separate volume or OS reprov
5月 12 18:00:01 kubernetes-m systemd[1]: docker-storage-setup.service: main process exited, code=exited, status=1/FAILURE
5月 12 18:00:01 kubernetes-m systemd[1]: Failed to start Docker Storage Setup.
-- Subject: Unit docker-storage-setup.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker-storage-setup.service has failed.
--
-- The result is failed.
5月 12 18:00:01 kubernetes-m systemd[1]: Unit docker-storage-setup.service entered failed state.
5月 12 18:00:01 kubernetes-m systemd[1]: docker-storage-setup.service failed.
5月 12 18:00:01 kubernetes-m systemd[1]: Starting Docker Application Container Engine...
解决办法:
[root@kubernetes-m ~]# vim /etc/selinux/config
把SELINUX=enforcing
改成SELINUX=disabled
reboot
[root@kubernetes-m ~]# systemctl start docker
[root@kubernetes-m ~]# systemctl start etcd
[root@kubernetes-m ~]# systemctl start kube-apiserver
[root@kubernetes-m ~]# systemctl start kube-controller-manager
[root@kubernetes-m ~]# systemctl start kube-scheduler
[root@kubernetes-m ~]# systemctl start kubelet
[root@kubernetes-m ~]# systemctl start kube-proxy
3、创建RC yaml文件
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: docker.io/kubeguide/mysql-master:latest
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
4、登录docker hub
[root@kubernetes-m yaml]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: xxxxxx
Password:
Login Succeeded
5、查找镜像
[root@kubernetes-m yaml]# docker search mysql-master
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/mysql MySQL is a widely used, open-source relati... 8128 [OK]
docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 2764 [OK]
docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 607 [OK]
docker.io docker.io/percona Percona Server is a fork of the MySQL rela... 432 [OK]
docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 192 [OK]
docker.io docker.io/mesosphere/mesos-master Mesos-Master in Docker 109
docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 101 [OK]
docker.io docker.io/mesoscloud/mesos-master Mesos Master 63 [OK]
docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 60 [OK]
docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 52
docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 44
docker.io docker.io/kubeguide/redis-master redis-master with "Hello World!" 29
docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 26 [OK]
docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 26 [OK]
docker.io docker.io/buildbot/buildbot-master Buildbot master dockerfile 24 [OK]
docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 22 [OK]
docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 11
docker.io docker.io/kubeguide/mysql-master mysql master 1 [OK]
docker.io docker.io/nacos/nacos-mysql-master nacos-mysql-master 1
docker.io docker.io/sage2/master SAGE2 master branch 1 [OK]
docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK]
docker.io docker.io/asterios/mysql-master mysql-master 0 [OK]
docker.io docker.io/asterios/mysql-master-ipb mysql-master-ipb 0 [OK]
docker.io docker.io/fluxcapacitor/sql-mysql-master 0
docker.io docker.io/ipunktbs/mysql-master MySQL Server configured to act as Master i... 0
我们需要docker.io/kubeguide/mysql-master这个镜像
6、下载镜像
[root@kubernetes-m yaml]# docker pull kubeguide/mysql-master
Using default tag: latest
Trying to pull repository docker.io/kubeguide/mysql-master ...
latest: Pulling from docker.io/kubeguide/mysql-master
27833a3ba0a5: Pull complete
864c283b3c4b: Pull complete
cea281b2278b: Pull complete
8f856c14f5af: Pull complete
9c4f38c23b6f: Pull complete
1b810e1751b3: Pull complete
5479aaef3d30: Pull complete
0f1430d39d4f: Pull complete
2bc64c824b3f: Pull complete
b64ec62ca852: Pull complete
42323e351ef3: Pull complete
3ba2d2c60f8a: Pull complete
1e0d62b6f70c: Pull complete
fb2f676c5455: Pull complete
bbd530bb64be: Pull complete
c80a8ae8fea1: Pull complete
5255a2bed2bd: Pull complete
ba0f6bd64ac5: Pull complete
90ccfe3a0b8e: Pull complete
55d51fbd6625: Pull complete
122b0eb94c1d: Pull complete
91cc530842b0: Pull complete
eb22ac617da1: Pull complete
f13872651400: Pull complete
Digest: sha256:ca0238707feccccb6a79a92982842ce247b45e5feba7f86d2c6e55afeab42a58
Status: Downloaded newer image for docker.io/kubeguide/mysql-master:latest
[root@kubernetes-m yaml]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/kubeguide/mysql-master latest d3b65700b52c 12 days ago 588 MB
6、创建pod
[root@kubernetes-m yaml]# kubectl create -f mysql-rc.yaml
replicationcontroller "mysql" created
但是发现只有rc,没有pod生成
[root@kubernetes-m yaml]# kubectl get pod
No resources found.
[root@kubernetes-m yaml]# kubectl get rc
NAME DESIRED CURRENT READY AGE
mysql 1 0 0 26s
查看rc的详情
[root@kubernetes-m yaml]# kubectl describe rc mysql
Name: mysql
Namespace: default
Image(s): docker.io/kubeguide/mysql-master:latest
Selector: app=mysql
Labels: app=mysql
Replicas: 0 current / 1 desired
Pods Status: 0 Running / 0 Waiting / 0 Succeeded / 0 Failed
No volumes.
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1m 4s 8 {replication-controller } Warning FailedCreate Error creating: No API token found for service account "default", retry after the token is automatically created and added to the service account
报错原因是service account没有设置api tocken导致的
解决办法:
[root@kubernetes-m yaml]# openssl genrsa -out /etc/kubernetes/serviceaccount.key 2048
[root@kubernetes-m yaml]# vim /etc/kubernetes/apiserver
添加
KUBE_API_ARGS="--service_account_key_file=/etc/kubernetes/serviceaccount.key"
[root@kubernetes-m yaml]# vim /etc/kubernetes/controller-manager
添加
KUBE_CONTROLLER_MANAGER_ARGS="--service_account_private_key_file=/etc/kubernetes/serviceaccount.key"
[root@kubernetes-m yaml]# systemctl restart etcd kube-apiserver kube-controller-manager kube-scheduler
[root@kubernetes-m yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-mn5mk 0/1 ContainerCreating 0 14s
但是发现该pod一直都是ContainerCreating的状态
[root@kubernetes-m yaml]# kubectl describe pod mysql-mn5mk
Name: mysql-mn5mk
Namespace: default
Node: 127.0.0.1/127.0.0.1
Start Time: Sun, 12 May 2019 18:43:59 +0800
Labels: app=mysql
Status: Pending
IP:
Controllers: ReplicationController/mysql
Containers:
mysql:
Container ID:
Image: docker.io/kubeguide/mysql-master:latest
Image ID:
Port: 3306/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9k8r4 (ro)
Environment Variables:
MYSQL_ROOT_PASSWORD: 123456
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-9k8r4:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9k8r4
QoS Class: BestEffort
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1m 1m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-mn5mk to 127.0.0.1
1m 30s 4 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"
1m 1s 5 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""
[root@kubernetes-m yaml]# yum install -y *rhsm*
[root@kubernetes-m yaml]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
[root@kubernetes-m yaml]# 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
[root@kubernetes-m ~]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
latest: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure
26e5ed6899db: Pull complete
66dbe984a319: Pull complete
9138e7863e08: Pull complete
Digest: sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931
Status: Image is up to date for registry.access.redhat.com/rhel7/pod-infrastructure:latest
删除pod,重新生成一个
[root@kubernetes-m yaml]# kubectl delete pod mysql-mn5mk
pod "mysql-mn5mk" deleted
[root@kubernetes-m yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-56n1x 0/1 ContainerCreating 0 3s
再次describe pod,发现已经可以正常下载镜像了
[root@kubernetes-m yaml]# kubectl describe pod mysql-wkcsm
Name: mysql-wkcsm
Namespace: default
Node: 127.0.0.1/127.0.0.1
Start Time: Sun, 12 May 2019 18:50:32 +0800
Labels: app=mysql
Status: Pending
IP:
Controllers: ReplicationController/mysql
Containers:
mysql:
Container ID:
Image: docker.io/kubeguide/mysql-master:latest
Image ID:
Port: 3306/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9k8r4 (ro)
Environment Variables:
MYSQL_ROOT_PASSWORD: 123456
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-9k8r4:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9k8r4
QoS Class: BestEffort
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
33s 33s 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-wkcsm to 127.0.0.1
[root@kubernetes-m yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-wkcsm 0/1 ContainerCreating 0 1m
[root@kubernetes-m yaml]# kubectl describe pod mysql-wkcsm
Name: mysql-wkcsm
Namespace: default
Node: 127.0.0.1/127.0.0.1
Start Time: Sun, 12 May 2019 18:50:32 +0800
Labels: app=mysql
Status: Pending
IP:
Controllers: ReplicationController/mysql
Containers:
mysql:
Container ID:
Image: docker.io/kubeguide/mysql-master:latest
Image ID:
Port: 3306/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Volume Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9k8r4 (ro)
Environment Variables:
MYSQL_ROOT_PASSWORD: 123456
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-9k8r4:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9k8r4
QoS Class: BestEffort
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1m 1m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-wkcsm to 127.0.0.1
等一段时间
[root@kubernetes-m yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-86t44 1/1 Running 1 10m
会有一个镜像
[root@kubernetes yaml]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/kubeguide/mysql-master latest d3b65700b52c 12 days ago 588 MB
registry.access.redhat.com/rhel7/pod-infrastructure latest 99965fb98423 19 months ago 209 MB
部署完成!
更多推荐
已为社区贡献2条内容
所有评论(0)