kubernetes安装配置部署及测试

来源:本站原创 Kubernetes 超过138 views围观 0条评论

https://feisky.gitbooks.io/kubernetes/  指南

https://www.kubernetes.org.cn/kubernetes-pod 中文说明

https://github.com/kubernetes/dashboard/

http://blog.51cto.com/douya/1945382  入门

———————-配置开始——————————————-

第一步组件安装
Master节点:
systemctl stop firewalld && sudo systemctl disable firewalld
yum install -y kubernetes etcd docker flannel    
 
Node节点:
systemctl stop firewalld && sudo systemctl disable firewalld
yum install -y kubernetes  docker flannel

节点
运行服务
 
 
 
—–Master
etcd
kube-apiserver
kube-controller-manager
kube-scheduler
kube-proxy
kubelet
docker
flanneld
 
 
—-node
flanneld
docker
kube-proxy
kubelet

Master:
hostnamectl set-hostname k8s_master
vi /etc/hosts
192.168.142.128   k8s_master
192.168.142.138   k8s_node1

 
etcd配置
vi /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
 
apiserver 配置
vi /etc/kubernetes/apiserver
KUBE_API_ADDRESS="–insecure-bind-address=0.0.0.0"   (apiserver绑定主机的非安全IP地址)
KUBE_API_PORT="–port=8080"                                          (apiserver绑定主机的非安全端口号)
KUBELET_PORT="–kubelet-port=10250"
KUBE_ETCD_SERVERS="–etcd-servers=http://192.168.142.128:2379"
KUBE_SERVICE_ADDRESSES="–service-cluster-ip-range=192.168.142.0/24" (虚机同一网段)
KUBE_ADMISSION_CONTROL="–admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_API_ARGS=""
 
Kubelet配置
vi /etc/kubernetes/kubelet
KUBELET_ADDRESS="–address=0.0.0.0"
KUBELET_PORT="–port=10250"
KUBELET_HOSTNAME="–hostname-override=192.168.142.128"
KUBELET_API_SERVER="–api-servers=http://192.168.142.128:8080"
KUBELET_POD_INFRA_CONTAINER="–pod-infra-Container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
 
config配置
vi /etc/kubernetes/config
KUBE_LOGTOSTDERR="–logtostderr=true"
KUBE_LOG_LEVEL="–v=0"
KUBE_ALLOW_PRIV="–allow-privileged=false"
KUBE_MASTER="–master=http://192.168.142.128:8080"
 
scheduler和 proxy 暂时没有用到,就不需要配置
 
flannel 配置
vi /etc/sysconfig/flanneld 
FLANNEL_ETCD="http://192.168.142.128:2379"
FLANNEL_ETCD_KEY="/atomic.io/network"
etcdctl  set修改get查询。不管是修改还是创建的时候,配置文件必须完整/coreos.com/network/config,要不然启动会报错。
添加网络:
systemctl enable etcd.service
systemctl start etcd.service
etcdctl mk //atomic.io/network/config ‘{"Network":"172.17.0.0/16"}’  创建
etcdctl rm //atomic.io/network/config ‘{"Network":"172.17.0.0/16"}’   删除
 
Master启动:
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler   kube-proxy  kubelet docker flanneld   ; do systemctl restart   $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES; done;
 
node配置:
 
hostnamectl set-hostname k8s_node1/2
 
Kubelet配置
vi   /etc/kubernetes/kubelet
KUBELET_ADDRESS="–address=0.0.0.0"
KUBELET_PORT="–port=10250"
KUBELET_HOSTNAME="–hostname-override=192.168.142.138"   (相应节点IP)
KUBELET_API_SERVER="–api-servers=http://192.168.142.128:8080"     (master节点IP)
KUBELET_POD_INFRA_CONTAINER="–pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=" "
 
config配置
vi  /etc/kubernetes/config 
KUBE_LOGTOSTDERR="–logtostderr=true"
KUBE_LOG_LEVEL="–v=0"
KUBE_ALLOW_PRIV="–allow-privileged=false"
KUBE_MASTER="–master=http://192.168.142.128:8080"
 
flannel 配置
vi  /etc/sysconfig/flanneld 
FLANNEL_ETCD="http://192.168.142.128:2379"
FLANNEL_ETCD_KEY="/atomic.io/network"
 
node启动
for SERVICES in kube-proxy kubelet docker flanneld; do
        systemctl restart $SERVICES
        systemctl enable $SERVICES
        systemctl status $SERVICES
    done;
 
 
查看所有NODE是否正常
kubectl -s 192.168.142.128:8080 get no
kubectl get nodes
 
 
访问http://kube-apiserver:port
http://192.168.142.128:8080/        查看所有请求url
http://192.168.142.128:8080/healthz/ping      查看健康状况

———————以上配置结束———————————–

——————-以下是排错及高级应用—————————

[root@k8s_master ~]# kubectl get namespaces  ——–查看所有namespace
NAME          STATUS    AGE
database      Active    23h
default       Active    1d
kube-system   Active    1d
[root@k8s_master ~]#

  kubectl get pod –all-namespaces   ———查看所有pod
 

[root@k8s_master ~]#   kubectl get pod –all-namespaces
NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
database      httpdtest-1nv30                         1/1       Running   3          22h
database      mysqltest1-w7fjr                        1/1       Running   3          22h
database      nginxtest2-3247366770-2kqlc             1/1       Running   0          12h
database      nginxtest2-3247366770-5jfrv             1/1       Running   0          12h
database      nginxtest2-3247366770-6bs0t             1/1       Running   0          12h
database      redisteset-5b993                        1/1       Running   1          14h
database      wordpresstest-c7d70                     1/1       Running   3          22h
default       nginx-pod                               1/1       Running   3          1d
kube-system   helloworld-jv2lm                        1/1       Running   2          23h
kube-system   kubernetes-dashboard-1471901517-c57dj   1/1       Running   0          13h
[root@k8s_master ~]#

 
  kubectl get service –namespace=kube-system  —–查看指定namespace 里的service

[root@k8s_master ~]#   kubectl get service –namespace=database
NAME            CLUSTER-IP        EXTERNAL-IP   PORT(S)          AGE
httpdtest       192.168.142.216   <pending>     80:31581/TCP     22h
mysqltest       192.168.142.136   <pending>     3306:32045/TCP   23h
mysqltest1      192.168.142.89    <pending>     3306:32052/TCP   22h
nginxtest2      192.168.142.235   <pending>     80:30498/TCP     12h
redisteset      192.168.142.80    <pending>     6379:30387/TCP   14h
wordpresstest   192.168.142.168   <pending>     80:32566/TCP     22h
[root@k8s_master ~]#

 
  kubectl get pods –namespace=kube-system  —-查看指定namspace里的pod
 

[root@k8s_master ~]#   kubectl get pods –namespace=database
NAME                          READY     STATUS    RESTARTS   AGE
httpdtest-1nv30               1/1       Running   3          22h
mysqltest1-w7fjr              1/1       Running   3          22h
nginxtest2-3247366770-2kqlc   1/1       Running   0          12h
nginxtest2-3247366770-5jfrv   1/1       Running   0          12h
nginxtest2-3247366770-6bs0t   1/1       Running   0          12h
redisteset-5b993              1/1       Running   1          14h
wordpresstest-c7d70           1/1       Running   3          22h
[root@k8s_master ~]#

  kubectl get pods –namespace=kube-system
  kubectl get  -f kubernetes-dashboard.yaml
 
 
 
  在master节点上启动

systemctl enable flanneld.service
systemctl start flanneld.service
service docker restart
systemctl restart kube-apiserver.service
systemctl restart kube-controller-manager.service
systemctl restart kube-scheduler.service

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler   kube-proxy  kubelet docker flanneld   ;
do systemctl restart   $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES; done;

在各个Nodes上启动

systemctl enable flanneld.service
systemctl start flanneld.service
service docker restart
systemctl restart kubelet.service
systemctl restart kube-proxy.service

node启动

for SERVICES in kube-proxy kubelet docker flanneld; do
        systemctl restart $SERVICES
        systemctl enable $SERVICES
        systemctl status $SERVICES
    done;
   
   

—————–部署nginx测试——————-
nginx-pod.yaml
   
    apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
  name: nginx-pod
spec:
containers:
– name: nginx
   image: nginx
   ports:
   – containerPort: 80

http://blog.csdn.net/u013760355/article/details/68061976   
[root@master ~]# kubectl create -f /opt/dockerconfig/nginx-pod.yaml
Error from server (ServerTimeout): error when creating "/opt/dockerconfig/nginx-pod.yaml": No API token found for service account "default", retry after the token is automatically created and added to the service account

报错是验证产生的

[root@master ~]# vim /etc/kubernetes/apiserver

去掉相应配置
#KUBE_ADMISSION_CONTROL="–admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_ADMISSION_CONTROL="–admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"

[root@master ~]# systemctl restart kube-apiserver
[root@master ~]#
解决

[root@master ~]# kubectl create -f /opt/dockerconfig/nginx-pod.yaml
pod "nginx-pod" created
[root@master ~]#

但是一直卡着
[root@master ~]# kubectl get pods
NAME        READY     STATUS              RESTARTS   AGE
nginx-pod   0/1       ContainerCreating   0          12m
[root@master ~]# kubectl get service
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   192.168.142.1   <none>        443/TCP   1h
[root@master ~]#
主要是通过“kubectl describe pod PodName”指令查看pod发生的事件,从事件列表中可以查找到错误信息
查状态
[root@master ~]# kubectl get pods
NAME        READY     STATUS              RESTARTS   AGE
nginx-pod   0/1       ContainerCreating   0          12m
[root@master ~]# kubectl get service
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   192.168.142.1   <none>        443/TCP   1h
[root@master ~]# kubectl describe pod gninx
Error from server (NotFound): pods "gninx" not found
[root@master ~]# kubectl describe pod nginx
Name:        nginx-pod
Namespace:    default
Node:        192.168.142.138/192.168.142.138
Start Time:    Thu, 18 Jan 2018 08:39:59 -0500
Labels:        name=nginx-pod
Status:        Pending
IP:       
Controllers:    <none>
Containers:
  nginx:
    Container ID:       
    Image:            nginx
    Image ID:           
    Port:            80/TCP
    State:            Waiting
      Reason:            ContainerCreating
    Ready:            False
    Restart Count:        0
    Volume Mounts:        <none>
    Environment Variables:    <none>
Conditions:
  Type        Status
  Initialized     True
  Ready     False
  PodScheduled     True
No volumes.
QoS Class:    BestEffort
Tolerations:    <none>
Events:
  FirstSeen    LastSeen    Count    From                SubObjectPath Type        Reason        Message
  ———    ——–    —–    —-                ————- ——–    ——        ——-
  15m        15m        1    {default-scheduler }                  Normal        Scheduled    Successfully assigned nginx-pod to 192.168.142.138
  15m        4m        7    {kubelet 192.168.142.138}              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)"

  14m    12s    64    {kubelet 192.168.142.138}        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\""

哈哈,你懂的
Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""
[root@master ~]#

手动下载
[root@master ~]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure …
open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory
[root@master ~]#

解决方法
[root@master ~]# yum install *rhsm* -y         —-安装

Installed:
  python-rhsm.x86_64 0:1.19.10-1.el7_4                                       python-rhsm-certificates.x86_64 0:1.19.10-1.el7_4                                     

Dependency Installed:
  python-dateutil.noarch 0:1.5-7.el7                                                                                                                                

Complete!
[root@master ~]#
[root@master ~]#
[root@master ~]# 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: Pulling fs layer
66dbe984a319: Pulling fs layer
^C38e7863e08: Pulling fs layer

等10个小时就好了
[root@master ~]#   kubectl get pods
NAME        READY     STATUS    RESTARTS   AGE
nginx-pod   1/1       Running   0          11h

 

新建nginx-service.
[root@master dockerconfig]# kubectl create -f nginx-service.yaml
service "nginx-service" created
[root@master dockerconfig]# kubectl get -f nginx-service.yaml
NAME            CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
nginx-service   192.168.142.65   <nodes>       80:30001/TCP   8s
[root@master dockerconfig]#

访问 node1的 30001端口测试成功

————安装dashboard————
http://docs.minunix.com/docker/kubernetes-dashboard.yaml 下载
http://www.jb51.net/article/94343.htm  案例

删除原有pod

[root@k8s_master dockerconfig]# kubectl get pods –all-namespaces  确认pod名字
NAMESPACE     NAME                                           READY     STATUS              RESTARTS   AGE
kube-system   kubernetes-dashboard-latest-3447225518-f39cr   0/1       ContainerCreating   0          9h

[root@k8s_master dockerconfig]# kubectl delete pod kubernetes-dashboard-latest-3447225518-f39cr –namespace=kube-system
pod "kubernetes-dashboard-latest-3447225518-f39cr" deleted

curl -o kubernetes-dashboard.yaml http://docs.minunix.com/docker/kubernetes-dashboard.yaml

镜像先用 docker search kubernetes-dashboard 进行搜索,确认版本后
         docker pull xxxx  
         docker images  查看需要的,再写入配置文件

下载后修改
   – –apiserver-host=http://192.168.142.128:8080  ## 请修改为自己的kebu-apiserver
   Image: docker.io/rainf/kubernetes-dashboard-amd64

[root@master dockerconfig]# kubectl create -f kubernetes-dashboard.yaml
deployment "kubernetes-dashboard" created
service "kubernetes-dashboard" created
[root@master dockerconfig]# kubectl get service
NAME            CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes      192.168.142.1    <none>        443/TCP        14h
nginx-service   192.168.142.65   <nodes>       80:30001/TCP   1h
[root@master dockerconfig]# kubectl get pods –namespace=kube-system
NAME                                           READY     STATUS             RESTARTS   AGE
kubernetes-dashboard-334721719-k4dn9           1/1       Running–运行中            0          42s
kubernetes-dashboard-latest-3447225518-gk7br   0/1       ImagePullBackOff   0          17m
[root@master dockerconfig]#

kubectl delete -f kubernetes-dashboard.yaml 删除,有需要可以执行

查看dashboard信息

[root@master dockerconfig]# kubectl describe pods kubernetes-dashboard-334721719-k4dn9  –namespace=kube-system
查看PODS详细信息的命令
Name:        kubernetes-dashboard-334721719-k4dn9
Namespace:    kube-system
Node:        192.168.142.138/192.168.142.138
Start Time:    Thu, 18 Jan 2018 21:16:01 -0500
Labels:        app=kubernetes-dashboard
        pod-template-hash=334721719
Status:        Running
IP:        172.17.13.3
Controllers:    ReplicaSet/kubernetes-dashboard-334721719
Containers:
  kubernetes-dashboard:
    Container ID:    docker://e376142b498b342099a655bcb02ba03a95a049c693750d0a1e8c547f7d127206
    Image:        daocloud.io/minunix/kubernetes-dashboard-amd64:v1.1.1
    Image ID:        docker-pullable://daocloud.io/minunix/kubernetes-dashboard-amd64@sha256:7fd7fd0e1aa84aecb62d62c10df0e8c4ed9cd80c538851962f058d708df06595
    Port:        9090/TCP
    Args:
      –apiserver-host=http://192.168.142.128:8080
    State:            Running
      Started:            Thu, 18 Jan 2018 21:16:12 -0500
    Ready:            True
    Restart Count:        0
    Liveness:            http-get http://:9090/ delay=30s timeout=30s period=10s #success=1 #failure=3
    Volume Mounts:        <none>
    Environment Variables:    <none>
Conditions:
  Type        Status
  Initialized     True
  Ready     True
  PodScheduled     True
No volumes.
QoS Class:    BestEffort
Tolerations:    <none>
Events:
  FirstSeen    LastSeen    Count    From                SubObjectPath                Type        Reason            Message
  ———    ——–    —–    —-                ————-                ——–    ——            ——-
  2m        2m        1    {default-scheduler }                            Normal        Scheduled        Successfully assigned kubernetes-dashboard-334721719-k4dn9 to 192.168.142.138
  2m        2m        1    {kubelet 192.168.142.138}    spec.containers{kubernetes-dashboard}    Normal        Pulling            pulling image "daocloud.io/minunix/kubernetes-dashboard-amd64:v1.1.1"
  2m        2m        2    {kubelet 192.168.142.138}                        Warning        MissingClusterDNS    kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  2m        2m        1    {kubelet 192.168.142.138}    spec.containers{kubernetes-dashboard}    Normal        Pulled            Successfully pulled image "daocloud.io/minunix/kubernetes-dashboard-amd64:v1.1.1"
  2m        2m        1    {kubelet 192.168.142.138}    spec.containers{kubernetes-dashboard}    Normal        Created            Created container with docker id e376142b498b; Security:[seccomp=unconfined]
  2m        2m        1    {kubelet 192.168.142.138}    spec.containers{kubernetes-dashboard}    Normal        Started            Started container with docker id e376142b498b
[root@master dockerconfig]#

在node1上查看docker信息

[root@k8s_node1 ~]# docker ps -a
CONTAINER ID        IMAGE                                                        COMMAND                  CREATED             STATUS              PORTS               NAMES
e376142b498b        daocloud.io/minunix/kubernetes-dashboard-amd64:v1.1.1        "/dashboard –port=90"   4 minutes ago       Up 4 minutes                            k8s_kubernetes-dashboard.b582b075_kubernetes-dashboard-334721719-k4dn9_kube-system_b1c339df-fcbe-11e7-a898-000c29027e38_040bd918
217259971f68        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           4 minutes ago       Up 4 minutes                            k8s_POD.28c50bab_kubernetes-dashboard-334721719-k4dn9_kube-system_b1c339df-fcbe-11e7-a898-000c29027e38_71496fa5
4773c9fc3ead        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           21 minutes ago      Up 21 minutes                           k8s_POD.28c50bab_kubernetes-dashboard-latest-3447225518-gk7br_kube-system_60816c6e-fcbc-11e7-a898-000c29027e38_94bd5ef7
[root@k8s_node1 ~]#

查看对外端口
[root@master dockerconfig]# kubectl get service –namespace=kube-system
NAME                   CLUSTER-IP        EXTERNAL-IP   PORT(S)        AGE
kubernetes-dashboard   192.168.142.252   <nodes>–在node       80:30949/TCP   10m
[root@master dockerconfig]#

 

通过页面访问
http://192.168.142.138:30949/#/pod/default/nginx-pod  直接访问node1的地址

http://192.168.142.128:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard/#/workload  通过master访问

———-使用dashboard进行APP部署————

新建  appname(helloworld)—image(nginx)—-extend—port(80)–targetport(80) –确定

[root@master dockerconfig]# kubectl get service –namespace=kube-system  ——-查看对外端口
NAME                   CLUSTER-IP        EXTERNAL-IP   PORT(S)        AGE
helloworld             192.168.142.153   <pending>     80:31675—端口/TCP   5m
kubernetes-dashboard   192.168.142.252   <nodes>       80:30949/TCP   1h
[root@master dockerconfig]#

测试一下
[root@master dockerconfig]# curl k8s_node1:31675
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
</html>      ——-成功
[root@master dockerconfig]#

————进行mysql部署————

前面是一样
[root@master dockerconfig]# kubectl describe pods –namespace=database
Name:        mysqltest-7ctnt
Namespace:    database
Node:        192.168.142.128/192.168.142.128
Start Time:    Thu, 18 Jan 2018 23:14:19 -0500
Labels:        app=mysqltest
Status:        Pending
IP:       
Controllers:    ReplicationController/mysqltest
Containers:
  mysqltest:
    Container ID:       
    Image:            mysql
    Image ID:           
    Port:           
    State:            Waiting
      Reason:            ContainerCreating
    Ready:            False
    Restart Count:        0
    Volume Mounts:        <none>
    Environment Variables:    <none>
Conditions:
  Type        Status
  Initialized     True
  Ready     False
  PodScheduled     True
No volumes.
QoS Class:    BestEffort
Tolerations:    <none>
Events:
  FirstSeen    LastSeen    Count    From                SubObjectPath            Type        Reason            Message
  ———    ——–    —–    —-                ————-            ——–    ——            ——-
  2m        2m        1    {default-scheduler }                        Normal        Scheduled        Successfully assigned mysqltest-7ctnt to 192.168.142.128
  2m        2m        1    {kubelet 192.168.142.128}                    Warning        MissingClusterDNS    kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  2m        2m        1    {kubelet 192.168.142.128}    spec.containers{mysqltest}    Normal        Pulling            pulling image "mysql"
[root@master dockerconfig]# kubectl get pods –namespace=database

[root@master ~]# kubectl describe pods –namespace=database
Name:        mysqltest-7ctnt
Namespace:    database
Node:        192.168.142.128/192.168.142.128
Start Time:    Thu, 18 Jan 2018 23:14:19 -0500
Labels:        app=mysqltest
Status:        Running
IP:        172.17.72.3
Controllers:    ReplicationController/mysqltest
Containers:
  mysqltest:
    Container ID:        docker://c7697c1c17742628c0fe5ee8ff8b0405866c5d0542e76e542e2863537bea985d
    Image:            mysql
    Image ID:            docker-pullable://docker.io/mysql@sha256:7cdb08f30a54d109ddded59525937592cb6852ff635a546626a8960d9ec34c30
    Port:           
    State:            Waiting
      Reason:            CrashLoopBackOff
    Last State:            Terminated
      Reason:            Error
      Exit Code:        1
      Started:            Thu, 18 Jan 2018 23:38:33 -0500
      Finished:            Thu, 18 Jan 2018 23:38:35 -0500
    Ready:            False
    Restart Count:        8
    Volume Mounts:        <none>
    Environment Variables:    <none>
Conditions:
  Type        Status
  Initialized     True
  Ready     False
  PodScheduled     True
No volumes.
QoS Class:    BestEffort
Tolerations:    <none>
Events:
  FirstSeen    LastSeen    Count    From                SubObjectPath            Type        Reason        Message
  ———    ——–    —–    —-                ————-            ——–    ——        ——-
  26m        26m        1    {default-scheduler }                        Normal        Scheduled    Successfully assigned mysqltest-7ctnt to 192.168.142.128
  19m        19m        1    {kubelet 192.168.142.128}    spec.containers{mysqltest}    Normal        Created        Created container with docker id 1face8a8e311; Security:[seccomp=unconfined]
  19m        19m        1    {kubelet 192.168.142.128}    spec.containers{mysqltest}    Normal        Started        Started container with docker id 1face8a8e311
  19m        19m        1    {kubelet 192.168.142.128}    spec.containers{mysqltest}    Normal        Created        Created container with docker id e14e935fc888; Security:[seccomp=unconfined]
  19m        19m        1    {kubelet 192.168.142.128}    spec.containers{mysqltest}    Normal        Started        Started container with docker id e14e935fc888
  19m        19m        2    {kubelet 192.168.142.128}                    Warning        FailedSync    Error syncing pod, skipping: failed to "StartContainer" for "mysqltest" with CrashLoopBackOff: "Back-off 10s restarting failed container=mysqltest pod=mysqltest-7ctnt_database(385572de-fccf-11e7-a898-000c29027e38)"

  这个错误基本上是 环境变量的问题在kubernetes dashboard上增加环境变为
 
  mysqltest1
Image:
mysql
Environment variables:
MYSQL_ROOT_PASSWORD: 123456    —加这个就好了

———-wordpress部署测试———–
wordpresstest
Image:
wordpress
Environment variables:
WORDPRESS_DB_HOST: 192.168.142.138:32052
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123456
WORDPRESS_DB_NAME: wordpress

kubernetes 展示的信息

Details
Name:
wordpresstest
Namespace:
database
Label selector:
app: wordpresstest
Labels:
app: wordpresstest
Images:
wordpress
Status
Pods:
1 running
Services
Name
Labels
Cluster IP
Internal endpoints
External endpoints
timelapse
wordpresstest
app: wordpresstest
192.168.142.168
wordpresstest.database:80 TCP   —–内部端口
wordpresstest.database:32566 TCP——对外端口

more_vert
Pods
Name
Status
Restarts
Age
Cluster IP
CPU (cores)
Memory (bytes)
check_circle
wordpresstest-c7d70
Running
0
55 minutes
172.17.72.9

测试一下
[root@master ~]# curl http://192.168.142.138:32566/ |less
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 53462    0 53462    0     0   321k      0 –:–:– –:–:– –:–:–  322k

正常

———-DOCKER加速器测试————-
http://guide.daocloud.io/dcs/docker-9153151.html 测试一下

 

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://b2ae5821.m.daocloud.io

运行后重启docker报错
[root@k8s_node1 ~]#  systemctl status docker
● docker.service – Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/docker.service.d
           └─flannel.conf
   Active: failed (Result: exit-code) since Thu 2018-01-18 23:25:07 EST; 32s ago
     Docs: http://docs.docker.com
  Process: 46222 ExecStart=/usr/bin/dockerd-current –add-runtime docker-runc=/usr/libexec/docker/docker-runc-current –default-runtime=docker-runc –exec-opt native.cgroupdriver=systemd –userland-proxy-path=/usr/libexec/docker/docker-proxy-current $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
Main PID: 46222 (code=exited, status=1/FAILURE)

Jan 18 23:25:07 k8s_node1 systemd[1]: Starting Docker Application Container Engine…
Jan 18 23:25:07 k8s_node1 dockerd-current[46222]: time="2018-01-18T23:25:07-05:00" level=fatal msg="unable to configure the Docker daemon with file /etc/…string\n"
Jan 18 23:25:07 k8s_node1 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Jan 18 23:25:07 k8s_node1 systemd[1]: Failed to start Docker Application Container Engine.
Jan 18 23:25:07 k8s_node1 systemd[1]: Unit docker.service entered failed state.
Jan 18 23:25:07 k8s_node1 systemd[1]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

原因是脚本修改 vim /etc/docker/daemon.json 有问题需要手动修改

——–daemon.json修改如下——-
{"registry-mirrors": ["http://b2ae5821.m.daocloud.io"], "insecure-registries": []
}
———daemon.jason修改完成————

查状态正常
[root@k8s_node1 ~]#  systemctl status docker
● docker.service – Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/docker.service.d
           └─flannel.conf
   Active: active (running) since Thu 2018-01-18 23:28:38 EST; 1min 43s ago
     Docs: http://docs.docker.com
Main PID: 48542 (dockerd-current)

———–查看pod在哪个node上——–
[root@k8s_master ~]# kubectl get pods -o wide  –namespace=database
NAME                          READY     STATUS    RESTARTS   AGE       IP            NODE—-就是这个你懂的
httpdtest-1nv30               1/1       Running   3          23h       172.17.72.5   192.168.142.128
mysqltest1-w7fjr              1/1       Running   3          23h       172.17.72.3   192.168.142.128
nginxtest2-3247366770-2kqlc   1/1       Running   0          13h       172.17.13.5   192.168.142.138
nginxtest2-3247366770-5jfrv   1/1       Running   0          13h       172.17.13.4   192.168.142.138
nginxtest2-3247366770-6bs0t   1/1       Running   0          13h       172.17.13.6   192.168.142.138
redisteset-5b993              1/1       Running   1          14h       172.17.13.2   192.168.142.138
wordpresstest-c7d70           1/1       Running   3          22h       172.17.72.2   192.168.142.128
[root@k8s_master ~]#

[root@k8s_master ~]# kubectl get -h   ——-其它的问它

——–进行拉取测试————

速度叼爆了
[root@k8s_node1 ~]# docker pull wordpress
Using default tag: latest
Trying to pull repository docker.io/library/wordpress …
latest: Pulling from docker.io/library/wordpress

75651f247827: Pull complete
dbcf8fd0150f: Pull complete
de80263f26f0: Pull complete
65be8ad4c5fd: Pull complete
239d5fed0dda: Pull complete
5ab39b683a9f: Pull complete
4a3f54f2d93a: Pull complete
28c970ad99e9: Pull complete
5d1e20c7c396: Pull complete
05f877a23903: Pull complete
e0a5c61bdaa6: Pull complete
d27d2d70a072: Pull complete
ba039fef4b7e: Pull complete
fd026e22f5c3: Pull complete
a523c6d55ab4: Pull complete
025590874132: Pull complete
2d4bd5336aa0: Pull complete
c014b4d902ee: Pull complete
Digest: sha256:73d85a7ae83ea7240090c3a52dbf176d610df2480c75c9e7fed8dba7e3d5154e

 

该脚本可以将 –registry-mirror 加入到你的 Docker 配置文件 /etc/docker/daemon.json 中。
适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有细微不同。更多详情请访问文档。

———版本1.7.3安装

https://www.cnblogs.com/liangDream/p/7358847.html

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=3688转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
下篇文章:木有了,已经是最新文章
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

快捷键:Ctrl+Enter