本人在虚拟机上部署了1master、2node的集群,想要使用本地打包的镜像hyperledger/fabric-orderer:1.4.3,一开始不清楚原因,只在master上安装了:
docker load -i fabric-orderer.tar
随后查看:
[root@k8s-master my-test]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-orderer 1.4.3 b666a6ebbe09 17 months ago 173 MB
然后创建测试fabric-orderer.yaml文件:
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-test
spec:
replicas: 2
template:
metadata:
labels:
k8s-app: fabric-orderer
spec:
containers:
- name: fabric-orderer-select-node1
image: hyperledger/fabric-orderer:1.4.3
imagePullPolicy: Never
ports:
- containerPort: 80
随后创建该deployment:
[root@k8s-master my-test]# kubectl create -f fabric-orderer.yaml
deployment "my-test" created
但是查看dashboard发现一片飘红,于是用命令查看:
[root@k8s-master my-test]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default my-test-66cf46b4d-cn7qr 0/1 ErrImageNeverPull 0 19s
default my-test-66cf46b4d-xgkqd 0/1 ErrImageNeverPull 0 19s
再具体一点:
[root@k8s-master my-test]# kubectl describe pod my-test-66cf46b4d-cn7qr
Name: my-test-66cf46b4d-cn7qr
Namespace: default
Node: k8s-node-2/192.168.203.203
Start Time: Tue, 26 Jan 2021 15:42:28 +0800
Labels: k8s-app=fabric-orderer
pod-template-hash=227902608
Annotations:
Status: Pending
IP:
Controlled By: ReplicaSet/my-test-66cf46b4d
Containers:
fabric-orderer-demo:
Container ID:
Image: fabric-orderer
Image ID:
Port:
State: Waiting
Reason: ErrImageNeverPull
Ready: False
Restart Count: 0
Environment:
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-bzrrv (ro)
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes:
default-token-bzrrv:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-bzrrv
Optional: false
QoS Class: BestEffort
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 52s default-scheduler Successfully assigned my-test-66cf46b4d-cn7qr to k8s-node-2
Normal SuccessfulMountVolume 51s kubelet, k8s-node-2 MountVolume.SetUp succeeded for volume "default-token-bzrrv"
Warning ErrImageNeverPull 32s (x8 over 49s) kubelet, k8s-node-2 Container image "fabric-orderer" is not present with pull policy of Never
Warning Failed 32s (x8 over 49s) kubelet, k8s-node-2 Error: ErrImageNeverPull
Normal SandboxChanged 31s (x8 over 49s) kubelet, k8s-node-2 Pod sandbox changed, it will be killed and re-created.
可以从最下面的Events看到两个warning,尤其是第一个,发现我的fabric-orderer没有部署上,理所应当的拉取不了,经过一顿查询:参考,每一个要使用该镜像的节点上都要事先docker load上该镜像,于是在k8s-node-1和k8s-node-2上:
docker load -i fabric-orderer.tar
随后再次:
[root@k8s-master my-test]# kubectl create -f fabric-orderer.yaml
deployment "my-test" created
这次成功了,当然这只是临时的用法,因为这样意味着你要把所有用到的镜像都打包好,部署到每个节点上。
不怕麻烦而且条件允许的话,还是创建一个本地镜像仓库为好(一劳永逸)。