创建 pod
cd ~
vi pod-demo.yaml
# 内容如下
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
- name: busybox
image: busybox:latest
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
# 使用 kubectl create 创建 pod
kubectl create -f pod-demo.yaml
# 这个 pod 里面有两个容器,一个是 myapp,一个是 busybox
# 查看日志
kubectl logs pod-demo myapp
# 进入 pod 中的容器内部
kubectl exec -it pod-demo -c myapp -- /bin/sh
创建 deployment
vi deploy-demo.yaml
# 内容如下
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deploy
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: myapp
release: canary
template:
metadata:
labels:
app: myapp
release: canary
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
ports:
- name: http
containerPort: 80
# 使用 kubectl apply 创建 deployment
kubectl apply -f deploy-demo.yaml
# 通过 kubectl describe 查看 deployment 信息
kubectl describe deploy myapp-deploy
创建 DeamonSet
vi ds-demo.yaml
# 内容如下
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: redis
role: logstor
template:
metadata:
labels:
app: redis
role: logstor
spec:
containers:
- name: redis
image: redis:4.0-alpine
ports:
- name: redis
containerPort: 6379
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: myapp-ds
namespace: default
spec:
selector:
matchLabels:
app: filebeat
release: stable
template:
metadata:
labels:
app: filebeat
release: stable
spec:
containers:
- name: filebeat
image: ikubernetes/filebeat:5.6.5-alpine
env:
- name: REDIS_HOST
value: redis.default.svc.cluster.local
- name: REDIS_LOG_LEVEL
value: info
原文地址:https://www.cnblogs.com/klvchen/p/9901514.html
时间: 2024-11-02 10:07:01