k create ns prod
k get ns prod
k create deployment app-server -n prod --image viktoruj/ping_pong --replicas 2 -o yaml --dry-run=client >1.yaml
# vim 1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: app-server
name: app-server
namespace: prod
spec:
replicas: 2
selector:
matchLabels:
app: app-server
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: app-server
spec:
containers:
- image: viktoruj/ping_pong
name: ping-pong # update it
env: # add it
- name: SRV_PORT # add it
value: "80" # add it
- name: SERVER_NAME # add it
value: "app-server" # add it
resources: {}
status: {}
#k get deployments.apps -n prod
NAME READY UP-TO-DATE AVAILABLE AGE
app-server 2/2 2 2 17s
# k get po -n prod
NAME READY STATUS RESTARTS AGE
app-server-86dd4cf6b5-47jq2 1/1 Running 0 24s
app-server-86dd4cf6b5-jqg8d 1/1 Running 0 24s
k expose deployment app-server --name app-server --port 80 -n prod
# k get svc -n prod
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
app-server ClusterIP 10.43.106.141 <none> 80/TCP 43s
# create pod for testing
k run test -n prod --image viktoruj/ping_pong:debug
# wait for the pod to be running
# k get po -n prod
NAME READY STATUS RESTARTS AGE
app-server-86dd4cf6b5-47jq2 1/1 Running 0 11m
app-server-86dd4cf6b5-jqg8d 1/1 Running 0 11m
test 1/1 Running 0 25s
# check the service
# k exec test -n prod -- sh -c 'curl app-server -s'
Server Name: app-server
URL: http://app-server/
Client IP: 10.42.0.11
Method: GET
Protocol: HTTP/1.1
Headers:
User-Agent: curl/8.3.0
Accept: */*