参照书本2.5章
https://blog.csdn.net/watermelonbig/article/details/79693962
配套yaml
https://github.com/kubeguide/samplecode/tree/master/Chapter2
遇到的问题:
用这个看日志kubectl logs -f kube-dns-v11-cndzm --namespace=kube-system -c skydns
总是创建pod失败,最后状态是镜像下载失败。
0;neal@neal:/home/neal/kubedns/kubedns[root@neal kubedns]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
kube-dns-v11-fd70k 0/4 ContainerCreating 0 58s
;neal@neal:/home/neal/kubedns/kubedns[root@neal kubedns]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
kube-dns-v11-fd70k 0/4 ErrImagePull 0 3m
研究发现是gcr.io无法连接,尝试各种vpn都没有用。不知道为什么。
后来找到一个办法,去dockerhub上翻垃圾,找别人传上去的镜像,找到之后替换yaml里的路径,下载就ok了。
PS:下面这个办法试了一下,貌似没用:
如果服务器可以访问外网,则可在docker daemon的启动参数中加上--insecure-registry gcr.io
1、修改docker配置文件(vim /etc/sysconfig/docker
)
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --registry-mirror=https://olzwzeg2.mirror.aliyuncs.com --insecure-registry gcr.io'
- 1
2、重启docker服务
$ systemctl restart docker
翻垃圾时,google_containers/ 这个不错,是官方去dockerhub上弄的,能找到一些。另外的就search找星级高的。下载的时候注意看看tag,因为有的没有latest,只有固定版本,要看看tag,否则也会获取失败。
下载陈宫之后,可以看到3个启动成功,还是有一个失败。
[root@neal kubedns]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
kube-dns-v11-z0n18 3/4 CrashLoopBackOff 29 1h
继续查看log。
[root@neal kubedns]# kubectl logs -f kube-dns-v11-z0n18 --namespace=kube-system -c skydns
2018/06/12 04:02:47 skydns: falling back to default configuration, could not read from etcd: 100: Key not found (/skydns) [3]
2018/06/12 04:02:47 skydns: ready for queries on cluster.local. for tcp://0.0.0.0:53 [rcache 0]
2018/06/12 04:02:47 skydns: ready for queries on cluster.local. for udp://0.0.0.0:53 [rcache 0]
找到一个报错。暂时没找到处理方法,准备换最新版本的kubedns再试试,现在装的是老的。
[root@neal kubedns]# kubectl dscribe pod kube-dns-v11-z0n18 --namespace=kube-system
Error: unknown command "dscribe" for "kubectl"
Did you mean this?
describe
Run 'kubectl --help' for usage.
Error: unknown command "dscribe" for "kubectl"
Did you mean this?
describe
unknown command "dscribe" for "kubectl"
Did you mean this?
describe
[root@neal kubedns]# kubectl describe pod kube-dns-v11-z0n18 --namespace=kube-system
Name: kube-dns-v11-z0n18
Namespace: kube-system
Node: 127.0.0.1/127.0.0.1
Start Time: Tue, 12 Jun 2018 12:02:31 +0800
Labels: k8s-app=kube-dns
kubernetes.io/cluster-service=true
version=v11
Status: Running
IP: 172.17.0.2
Controllers: ReplicationController/kube-dns-v11
Containers:
etcd:
Container ID: docker://3996d8329f47eb67c4abddd6b2515e716642b0447461a50752b61f6c9348391d
Image: docker.io/googlecontainer/etcd-amd64:2.2.1
Image ID: docker-pullable://docker.io/googlecontainer/etcd-amd64@sha256:c300862b4dd65df901327762bb7bd19a441dacf1ef1184cc78b86407d30ba71c
Port:
Command:
/usr/local/bin/etcd
-data-dir
/tmp/data
-listen-client-urls
http://127.0.0.1:2379,http://127.0.0.1:4001
-advertise-client-urls
http://127.0.0.1:2379,http://127.0.0.1:4001
-initial-cluster-token
skydns-etcd
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 100m
memory: 50Mi
State: Running
Started: Tue, 12 Jun 2018 12:02:42 +0800
Ready: True
Restart Count: 0
Volume Mounts:
/tmp/data from etcd-storage (rw)
Environment Variables: <none>
kube2sky:
Container ID: docker://3a78ba4cf5a9af2834f7c23d683fad5dd155e97749222117d7086ae4df12ac17
Image: docker.io/googlecontainer/kube2sky-amd64:1.15
Image ID: docker-pullable://docker.io/googlecontainer/kube2sky-amd64@sha256:e20f93d98cc5fbfd14d4b323c8704cfb920556f586c322bf2acd57bc0809931b
Port:
Args:
--kube-master-url=http://192.168.102.132:8080
--domain=cluster.local
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 100m
memory: 50Mi
State: Running
Started: Tue, 12 Jun 2018 14:10:21 +0800
Last State: Terminated
Reason: Error
Exit Code: 255
Started: Tue, 12 Jun 2018 14:04:03 +0800
Finished: Tue, 12 Jun 2018 14:05:12 +0800
Ready: False
Restart Count: 38
Liveness: http-get http://:8080/healthz delay=60s timeout=5s period=10s #success=1 #failure=5
Readiness: http-get http://:8081/readiness delay=30s timeout=5s period=10s #success=1 #failure=3
Volume Mounts: <none>
Environment Variables: <none>
skydns:
Container ID: docker://ef9a2bf8b4e4be3bcdc62c596b5e8402372a975ef0476d0383ca077e9208cb71
Image: docker.io/skynetservices/skydns
Image ID: docker-pullable://docker.io/skynetservices/skydns@sha256:6f8a9cff0b946574bb59804016d3aacebc637581bace452db6a7515fa2df79ee
Ports: 53/UDP, 53/TCP
Args:
-machines=http://127.0.0.1:4001
-addr=0.0.0.0:53
-ns-rotate=false
-domain=cluster.local
Limits:
cpu: 100m
memory: 50Mi
Requests:
cpu: 100m
memory: 50Mi
State: Running
Started: Tue, 12 Jun 2018 12:02:47 +0800
Ready: True
Restart Count: 0
Volume Mounts: <none>
Environment Variables: <none>
healthz:
Container ID: docker://ba698e0b47a0536b92b661c9a436531d63be249f5c27f83241bea6b96fc54457
Image: docker.io/mritd/exechealthz-amd64
Image ID: docker-pullable://docker.io/mritd/exechealthz-amd64@sha256:9ed5bfaf7d1c088c652646fb013fab5c646f3b6152fe1bcb7fb4ebae3ddf6285
Port: 8080/TCP
Args:
-cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null
-port=8080
Limits:
cpu: 10m
memory: 20Mi
Requests:
cpu: 10m
memory: 20Mi
State: Running
Started: Tue, 12 Jun 2018 12:03:00 +0800
Ready: True
Restart Count: 0
Volume Mounts: <none>
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
etcd-storage:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
QoS Class: Guaranteed
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
1h 6m 29 {kubelet 127.0.0.1} spec.containers{kube2sky} Normal Killing (events with common reason combined)
2h 6m 42 {kubelet 127.0.0.1} spec.containers{kube2sky} Warning Unhealthy Liveness probe failed: HTTP probe failed with statuscode: 503
1h 1m 383 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "kube2sky" with CrashLoopBackOff: "Back-off 5m0s restarting failed container=kube2sky pod=kube-dns-v11-z0n18_kube-system(6e455c7a-6df5-11e8-8c11-000c298999d9)"
2h 1m 391 {kubelet 127.0.0.1} spec.containers{kube2sky} Warning BackOff Back-off restarting failed docker container
1h 58s 33 {kubelet 127.0.0.1} spec.containers{kube2sky} Normal Created (events with common reason combined)
1h 58s 33 {kubelet 127.0.0.1} spec.containers{kube2sky} Normal Started (events with common reason combined)
2h 58s 39 {kubelet 127.0.0.1} spec.containers{kube2sky} Normal Pulled Container image "docker.io/googlecontainer/kube2sky-amd64:1.15" already present on machine
2h 8s 159 {kubelet 127.0.0.1} spec.containers{kube2sky} Warning Unhealthy Readiness probe failed: Get http://172.17.0.2:8081/readiness: dial tcp 172.17.0.2:8081: getsockopt: connection refused
[root@neal kubedns]#