1 编写配置文件以及pod创建过程
[root@k8s-master yaml]# cat ceph-rbd-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-ceph-rbd
spec:
selector:
matchLabels:
app: nginx-ceph-rbd
replicas: 2
template:
metadata:
labels:
app: nginx-ceph-rbd
spec:
containers:
- name: nginx-ceph-rbd
image: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: nginx-ceph-rbd
volumes:
- name: nginx-ceph-rbd
persistentVolumeClaim:
claimName: ceph-pvc-test
[root@k8s-master yaml]#
配置生效
[root@k8s-master yaml]#
[root@k8s-master yaml]# kubectl apply -f ceph-rbd-deployment.yaml
deployment.apps/nginx-ceph-rbd created
[root@k8s-master yaml]#
[root@k8s-master yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-ceph-rbd-6cdb6df67f-p4xr8 1/1 Running 0 34m
nginx-ceph-rbd-6cdb6df67f-v4p6b 1/1 Running 0 34m
[root@k8s-master yaml]#
[root@k8s-master yaml]# kubectl logs nginx-ceph-rbd-6cdb6df67f-p4xr8
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/08/09 03:41:38 [notice] 1#1: using the "epoll" event method
2022/08/09 03:41:38 [notice] 1#1: nginx/1.23.1
2022/08/09 03:41:38 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/08/09 03:41:38 [notice] 1#1: OS: Linux 3.10.0-1160.el7.x86_64
2022/08/09 03:41:38 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/08/09 03:41:38 [notice] 1#1: start worker processes
2022/08/09 03:41:38 [notice] 1#1: start worker process 30
[root@k8s-master yaml]#
[root@k8s-master yaml]#
[root@k8s-master yaml]# kubectl describe pod nginx-ceph-rbd-6cdb6df67f-p4xr8
Name: nginx-ceph-rbd-6cdb6df67f-p4xr8
Namespace: default
Priority: 0
Node: k8s-node1/192.168.1.101
Start Time: Tue, 09 Aug 2022 11:23:31 +0800
Labels: app=nginx-ceph-rbd
pod-template-hash=6cdb6df67f
Annotations: cni.projectcalico.org/podIP: 10.244.36.70/32
cni.projectcalico.org/podIPs: 10.244.36.70/32
Status: Running
IP: 10.244.36.70
IPs:
IP: 10.244.36.70
Controlled By: ReplicaSet/nginx-ceph-rbd-6cdb6df67f
Containers:
nginx-ceph-rbd:
Container ID: docker://85201c20785e8e19dcb500dddf0089085bc3d1bb76c771c2329708c35749bd3f
Image: nginx
Image ID: docker-pullable://nginx@sha256:ecc068890de55a75f1a32cc8063e79f90f0b043d70c5fcf28f1713395a4b3d49
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 09 Aug 2022 11:41:39 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/usr/share/nginx/html from nginx-ceph-rbd (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-vszlv (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
nginx-ceph-rbd:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: ceph-pvc-test
ReadOnly: false
kube-api-access-vszlv:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 28m default-scheduler Successfully assigned default/nginx-ceph-rbd-6cdb6df67f-p4xr8 to k8s-node1
Normal SuccessfulAttachVolume 28m attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-d9656b0f-4f0a-4071-b26f-65dd03ce9da6"
Normal Pulling 26m kubelet Pulling image "nginx"
Normal Pulled 11m kubelet Successfully pulled image "nginx" in 15m32.457150985s
Normal Created 11m kubelet Created container nginx-ceph-rbd
Normal Started 10m kubelet Started container nginx-ceph-rbd
Warning FailedMount 9m25s kubelet MountVolume.SetUp failed for volume "kube-api-access-vszlv" : failed to sync configmap cache: timed out waiting for the condition
Warning NodeNotReady 3m30s node-controller Node is not ready
[root@k8s-master yaml]#
2 进入容器检查数据
[root@k8s-master yaml]# kubectl exec -it nginx-ceph-rbd-6cdb6df67f-jjmrn sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
#
# cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.244.169.138 nginx-ceph-rbd-6cdb6df67f-jjmrn
#
# hostname
nginx-ceph-rbd-6cdb6df67f-jjmrn
#
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 27G 7.3G 20G 27% /
tmpfs tmpfs 64M 0 64M 0% /dev
tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 27G 7.3G 20G 27% /etc/hosts
shm tmpfs 64M 0 64M 0% /dev/shm
/dev/rbd0 ext4 976M 2.6M 958M 1% /usr/share/nginx/html
tmpfs tmpfs 1.7G 12K 1.7G 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs tmpfs 910M 0 910M 0% /proc/acpi
tmpfs tmpfs 910M 0 910M 0% /proc/scsi
tmpfs tmpfs 910M 0 910M 0% /sys/firmware
#