[root@k8s-master-01 deploy]# kubectl create deploy mydeploy --image=nginx --dry-run -o yaml
W0212 15:36:32.387488 98337 helpers.go:598] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: mydeploy
name: mydeploy
spec:
replicas: 1
selector:
matchLabels:
app: mydeploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mydeploy
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
#查看coredns的deployment
[root@k8s-master-01 deploy]# kubectl get deploy coredns -n kube-system -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2022-02-08T09:43:50Z"
generation: 1
labels:
k8s-app: kube-dns
name: coredns
namespace: kube-system
resourceVersion: "142085"
uid: 90efabe9-c12d-4dcd-8199-4e2b93bbf25f
spec:
progressDeadlineSeconds: 600
replicas: 2
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: kube-dns
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
k8s-app: kube-dns
spec:
containers:
- args:
- -conf
- /etc/coredns/Corefile
image: registry.aliyuncs.com/google_containers/coredns:v1.8.6
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 5
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: coredns
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9153
name: metrics
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /ready
port: 8181
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 170Mi
requests:
cpu: 100m
memory: 70Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_BIND_SERVICE
drop:
- all
readOnlyRootFilesystem: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/coredns
name: config-volume
readOnly: true
dnsPolicy: Default
nodeSelector:
kubernetes.io/os: linux
priorityClassName: system-cluster-critical
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: coredns
serviceAccountName: coredns
terminationGracePeriodSeconds: 30
tolerations:
- key: CriticalAddonsOnly
operator: Exists
- effect: NoSchedule
key: node-role.kubernetes.io/master
- effect: NoSchedule
key: node-role.kubernetes.io/control-plane
volumes:
- configMap:
defaultMode: 420
items:
- key: Corefile
path: Corefile
name: coredns
name: config-volume
status:
availableReplicas: 2
conditions:
- lastTransitionTime: "2022-02-08T09:44:06Z"
lastUpdateTime: "2022-02-08T09:45:22Z"
message: ReplicaSet "coredns-6d8c4cb4d" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
- lastTransitionTime: "2022-02-12T03:41:56Z"
lastUpdateTime: "2022-02-12T03:41:56Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration: 1
readyReplicas: 2
replicas: 2
updatedReplicas: 2
[root@k8s-master-01 deploy]# more mydeploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: mydeploy
name: mydeploy
spec:
replicas: 1
selector:
matchLabels:
app: mydeploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mydeploy
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
[root@k8s-master-01 deploy]# kubectl apply -f mydeploy.yaml
deployment.apps/mydeploy created
[root@k8s-master-01 deploy]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
mydeploy 1/1 1 1 25s
[root@k8s-master-01 deploy]# kubectl expose deploy mydeploy --name=mysvc --port=80 --target-port=80
service/mysvc exposed
[root@k8s-master-01 deploy]# kubectl autoscale deploy mydeploy --max=5 --cpu-percent=80
horizontalpodautoscaler.autoscaling/mydeploy autoscaled
#更新镜像
[root@k8s-master-01 deploy]# kubectl set image deploy mydeploy nginx=nginx:1.7.9
deployment.apps/mydeploy image updated
#查看版本
[root@k8s-master-01 deploy]# kubectl rollout history deploy mydeploy
deployment.apps/mydeploy
REVISION CHANGE-CAUSE
1 <none>
2 <none>
[root@k8s-master-01 deploy]# kubectl set image deploy mydeploy nginx=nginx:latest --record=true
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/mydeploy image updated
[root@k8s-master-01 deploy]# kubectl rollout history deploy mydeploy
deployment.apps/mydeploy
REVISION CHANGE-CAUSE
1 <none>
2 <none>
3 kubectl set image deploy mydeploy nginx=nginx:latest --record=true
#回滚
[root@k8s-master-01 deploy]# kubectl rollout undo deploy mydeploy --to-revision=2
deployment.apps/mydeploy rolled back
#端口类型
[root@k8s-master-01 deploy]# kubectl get svc kubernetes -n default -o yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2022-02-08T09:43:48Z"
labels:
component: apiserver
provider: kubernetes
name: kubernetes
namespace: default
resourceVersion: "209"
uid: 83ca0df2-0083-4d24-9f71-9944d6a934d6
spec:
clusterIP: 10.96.0.1
clusterIPs:
- 10.96.0.1
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: https
port: 443 #service的端口
protocol: TCP
targetPort: 6443 #后端容器暴露的端口
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
K8S Delpoyment创建、编辑和回滚
于 2022-02-12 16:54:46 首次发布