yml
apiVersion: v1
kind: Namespace
metadata:
name: idms
yml
apiVersion: v1
kind: Pod
metadata:
# pod 的名字
name: mynginx
# 指定命名空间 可选
namespace: idms
labels:
app: mynginx
spec:
containers:
- image: nginx
name: mynginx
# kubectl run mynginx --image=nginx --port=80
# kubectl describe pod mynginx
# kubectl describe pod mynginx -n idms
# kubectl delete -f pod.yml
# kubectl logs mynginx
# kubectl exec -it mynginx -n idms -- /bin/bash
# curl 10.244.2.51:80
yml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: idms
labels:
app: mynginx-deploy
name: mynginx
spec:
replicas: 1
selector:
matchLabels:
app: mynginx
template:
metadata:
labels:
app: mynginx
spec:
containers:
- image: nginx
name: mynginx
yml
apiVersion: v1
kind: Service
metadata:
name: mynginx-svc
namespace: idms
labels:
app: mynginx-svc
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
#name: mynginx-service
# nodePort: 30001
type: NodePort # ClusterIP NodePort ClusterIP
selector:
app: mynginx
python
apiVersion: v1
kind: Namespace
metadata:
name: idms
labels:
name: idms
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
namespace: idms
labels:
app: mynginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- name: conf
mountPath: /etc/nginx/
- name: log
mountPath: /var/log/nginx
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: conf
hostPath:
path: /opt/k8s/nginx/
type: DirectoryOrCreate
- name: log
hostPath:
path: /opt/k8s/nginx/log
type: DirectoryOrCreate
- name: html
hostPath:
path: /opt/k8s/nginx/html
type: DirectoryOrCreate
python
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-rs
spec:
replicas: 2
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx
python
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod2
labels:
app: nginx-pod2
spec:
affinity:
# 反 亲和性
podAntiAffinity:
# 硬限制
requiredDuringSchedulingIgnoredDuringExecution:
# 调度到 和 nginx-pod 不同的机器上
- topologyKey: "kubernetes.io/hostname"
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- nginx-pod
# preferredDuringSchedulingIgnoredDuringExecution:
# - weight: 100
# podAffinityTerm:
# labelSelector:
# matchExpressions:
# - key: app
# operator: In
# values:
# - nginx-pod
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
protocol: TCP
nfs pod
python
apiVersion: v1
kind: Namespace
metadata:
name: idms
labels:
name: idms
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
namespace: idms
labels:
app: mynginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- name: log
mountPath: /var/log/nginx
volumes:
- name: log
nfs:
server: 192.168.83.134
path: /nfs/data/idms
configmap
shell
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
namespace: default
data:
redis.host: localhost
redis.port: 6379
# 使用 | 符号表示值是多行文本,这种格式可以保持文本的格式不变。
apiVersion: v1
kind: Pod
metadata:
name: pod-nginx
spec:
# command: ["sh", "-c", "touch /configmap/redis.conf"]", ]
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- name: nginx-conf
mountPath: /configmap/redis.conf
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
secret
shell
apiVersion: v1
kind: Secret
metadata:
name: mynginx-secret
type: Opaque
data:
username: bXlhZG1pbg==
password: YWRtaW4=
---
apiVersion: v1
kind: Pod
metadata:
name: pod-nginx2
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- name: nginx-conf
mountPath: /secret/
readOnly: true
volumes:
- name: nginx-conf
secret:
secretName: mynginx-secret