apiVersion: v1
kind: Pod
metadata:
name: nginx01
labels:
app: nginx
namespace: qhtest
spec:
containers:
- name: nginx01
image: nginx:qh
ports:
- containerPort: 80
dnsConfig:
nameservers:
- 202.103.224.68
- 8.8.8.8
kubectr namesapce create qhtest
ctr -n k8s.io image import nginx.tar
kubectl apply -f test.yaml
kubectl get pods -n qhtest
kubectl -n qhtest delete pod nginx01
kubectl get pods -n test1
kubectl run my-pod --image=myimage:mytag --restart=Never
docker pull hub.atomgit.com/amd64/nginx:1.25.2-perl
apiVersion: v1
kind: Service
metadata:
name: my-service
labels:
app: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 8018
targetPort: 80
kubectl get svc
kubectl get endpoints
创建PV使得NFS
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
nfs:
path: /path/to/nfs/volume
server: nfs-server-ip
创建PV使用LOCAL
storageclass_local.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv01
spec:
capacity:
storage: 3Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local
local:
path: /disks/vol1 #将本地磁盘作为目录,事先存在。
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname #匹配的节点标签
operator: In
values:
- worker #PV绑定的节点名称
在POD的第一个容器执行命令
kubectl exec nginx02 -- date
在POD的指定容器执行命令
kubectl exec nginx02 nginx01 -- date
kubectl exec -ti nginx02 -- /bin/bash