Deploy a pod named nginx-448839 using the nginx:alpine image
kubectl run nginx-448839 --image=nginx:alpine
Create a namespace named apx-z993845
kubectl create ns apx-z993845
Create a new deployment named httpd-frontend with 3 replicas using image httpd:2.4-alpine
kubectl create deployment httpd-frontend --image=httpd:2.4-alpine --replicas=3
Deploy a messaging pod using the redis:alpine image with the labels set to tier=msg
kubectl run messaging --image=redis:alpine --restart=Never
A replicaset rs-d33393 is created. However the pods are not coming up. Identify and fix the issue.
kubectl describe rs rs-d33393
# Notice the image is bad
# update the yaml
kubectl get rs rs-33393 -o yaml > rs.yaml
kubectl edit rs rs-33393
#update the image from image:busyboxXXXXXX to image: busybox
# Delete the pods from the RS so they can be recreated with the new image
Create a service messaging-service to expose the redis deployment in the marketing namespace within the cluster on port 6379.
k -n marketing expose deployment redis --name messaging-service --port 6379 --target-port 6379 --dry-run=client -o yaml > svc.yaml
#
# Add Namespace
apiVersion: v1
kind: Service
metadata:
name: messaging-service
namespace: marketing
spec:
ports:
- port: 6379
protocol: TCP
targetPort: 6379
selector:
name: redis-pod
status:
loadBalancer: {}
Describe should look like this
kubectl describe -n marketing svc messaging-service
Name: messaging-service
Namespace: marketing
Labels: <none>
Annotations: <none>
Selector: name=redis-pod
Type: ClusterIP
IP Families: <none>
IP: 10.109.81.163
Port: <unset> 6379/TCP
TargetPort: 6379/TCP
Endpoints: 10.32.0.5:6379
Session Affinity: None
Events: <none>
Update the environment variable on the pod webapp-color to use a green background
# Save the yaml to a file and then update the env variable in the file.
# Delete the current pod and then create a new pod with the saved/modified yaml.
kubectl describe pod webapp-color -o yaml > pod.yaml
edit
kubectl delete po webapp-color
kubectl create -f pod.yaml
Create a new ConfigMap named cm-3392845. Use the spec given on the right.
ConfigName Name: cm-3392845
Data: DB_NAME=SQL3322
Data: DB_HOST=sql322.mycompany.com
Data: DB_PORT=3306
k create configmap cm-3392845 --from-literal=DB_NAME=SQL3322 --from-literal=DB_HOST=sql322.mycompany.com --from-literal=DB_PORT=3306
Create a new Secret named db-secret-xxdf with the data given(on the right).
Secret Name: db-secret-xxdf
Secret 1: DB_Host=sql01
Secret 2: DB_User=root
Secret 3: DB_Password=password123
k create secret generic db-secret-xxdf --from-literal=DB_Host=sql01 --from-literal=DB_User=root --from-literal=DB_Password=password123
Update pod app-sec-kff3345 to run as Root user and with the SYS_TIME capability
# Get pod config
kubectl get po app-sec-kff3345 -o yaml > pod.yaml
edit pod.yaml
# after the spec in the pod, add:
securityContext:
runAsUser: 0 #root
# In the container section, add
securityContext:
capabilities:
add: ["SYS_TIME"]
Export the logs of the e-com-1123 pod to the file /opt/outputs/e-com-1123.logs
kubectl get pods --all-namespaces|grep e-com-1123
kubectl -n e-commerce logs e-com-1123 > /opt/outputs/e-com-1123.logs
Create a Persistent Volume with the following specs:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
spec:
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
hostPath:
path: /pv/data-analytics
Create a redis deployment using the image redis:alpine with 1 replica and label app=redis. Expose it via a ClusterIP service called redis on port 6379. Create a new Ingress Type NetworkPolicy called redis-access which allows only the pods with label access=redis to access the deployment.
kubectl create deployment redis --image=redis:alpine --replicas=1
#label will be applied when deployment is created
kubectl expose deployment redis --target-port 6379 --port 6379
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: redis-access
namespace: default
spec:
podSelector:
matchLabels:
app: redis
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
access: redis
ports:
- protocol: TCP
port: 6379
Create a Pod called sega with two containers:
Container 1: Name tails with image busybox and command: sleep 3600.
Container 2: Name sonic with image nginx and Environment variable: NGINX_PORT with the value 8080.
k run sega --image=busybox --dry-run=client -o yaml -- /bin/sh -c "sleep 3600" > sega.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: sega
name: sega
spec:
containers:
- args:
- /bin/sh
- -c
- sleep 3600
image: busybox
name: tails
- name: sonic
image: nginx
env:
- name: NGINX_PORT
value: "8080"