Skip to content

Instantly share code, notes, and snippets.

View sarjarapu's full-sized avatar

sarjarapu

  • Amazon Web Services
  • Austin, TX
View GitHub Profile
@sarjarapu
sarjarapu / kubernetes-recreate.operator.sh
Created July 11, 2018 20:56
A kubectl command to recreate the MongoDB Enterprise Operator pod
# delete the existing pod after fixing the issue
kubectl -n mongodb delete pod $K8_OPERATOR_POD_NAME
sleep 5
# display all the resources in the namespace
kubectl -n ${K8_NAMESPACE} get all
@sarjarapu
sarjarapu / kubernetes-troubleshoot.operator.sh
Created July 11, 2018 20:54
A kubectl command to check the logs for MongoDB Enterprise Operator pod
# find the pod name for mongodb-enterprise-operator using selectors
K8_OPERATOR_POD_NAME=$(kubectl -n mongodb get pods --selector=app=mongodb-enterprise-operator --output=jsonpath='{.items[0].metadata.name}')
# display the mongodb-enterprise-operator logs from mongodb namespace
kubectl -n mongodb logs $K8_OPERATOR_POD_NAME
@sarjarapu
sarjarapu / kubernetes-delete.replicaset.sh
Created July 11, 2018 20:52
A kubectl command to remove the MongoDbReplicaSet from Kubernetes and Ops Manager
kubectl delete -f samples/${K8_NAMESPACE}-replicaset.yaml
@sarjarapu
sarjarapu / kubernetes-external.connectivity.sh
Created July 11, 2018 20:48
A bash script showing the connectivity to the MongoDB replica set member using NodePort
kubectl -n ${K8_NAMESPACE} describe pod/mongodb-world-replicaset-0 | grep 'Node:'
# Node: 10.128.0.7
kubectl -n ${K8_NAMESPACE} get services
# NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
# mongodb-world-replicaset-svc ClusterIP None <none> 27017/TCP 41m
# mongodb-world-replicaset-svc-external NodePort 10.43.252.153 <none> 27017:31750/TCP 41m
mongo --host 10.128.0.7 --port 31750
# MongoDB shell version v3.6.5
# connecting to: mongodb://mongodb-world-replicaset-0:27017/
# MongoDB server version: 3.6.5
@sarjarapu
sarjarapu / kubernetes-connectivity.sh
Created July 11, 2018 20:47
A bash script showing the connectivity to the MongoDB replica set member via mongo shell
kubectl -n ${K8_NAMESPACE} exec -it ${K8_NAMESPACE}-replicaset-0 -- bin/bash
# mongodb@mongodb-world-replicaset-0:/$
/var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.6.5/bin/mongo
# MongoDB shell version v3.6.5
# connecting to: mongodb://mongodb-world-replicaset-0:27017/
# MongoDB server version: 3.6.5
# mongodb-world-replicaset:PRIMARY>
@sarjarapu
sarjarapu / kubernetes-replicaset.yaml
Last active August 5, 2018 16:16
The auto generated YAML file for creating namespace, configmap, secret and MongoDbReplicaSet
# mongodb-world-replicaset.yaml contents
---
apiVersion: v1
kind: Namespace
metadata:
name: "mongodb-world"
---
apiVersion: v1
kind: ConfigMap
metadata:
@sarjarapu
sarjarapu / kubernetes-display.resources.sh
Created July 11, 2018 20:38
A kubectl command to list all the resources that the helper script has created
# display all the resources in the namespace
kubectl -n $K8_NAMESPACE get all
# NAME READY STATUS RESTARTS AGE
# pod/mongodb-world-replicaset-0 1/1 Running 0 4m
# pod/mongodb-world-replicaset-1 1/1 Running 0 4m
# pod/mongodb-world-replicaset-2 1/1 Running 0 4m
#
# NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) # AGE
# service/mongodb-world-replicaset-svc ClusterIP None <none> 27017/TCP # 4m
# service/mongodb-world-replicaset-svc-external NodePort 10.43.252.153 <none> # 27017:31750/TCP 4m
@sarjarapu
sarjarapu / kubernetes-create.replicaset.sh
Created July 11, 2018 20:37
Shell commands to generate and apply the YAML file to create the MongoDB replica set.
# create the YAML file using the template
sh templates/generate-yaml-simple-replicaset.sh
# create the replica set based on the generated YAML
source templates/environment.sh
kubectl apply -f samples/${K8_NAMESPACE}-replicaset.yaml
@sarjarapu
sarjarapu / kubernetes-environment.example.sh
Created July 11, 2018 20:34
An example script with environment variables set for Ops Manager Url, Kubernetes namespace and MongoDB version
OM_URL="https://cloud.mongodb.com/"
K8_NAMESPACE="mongodb-world"
MONGODB_VERSION="3.6.5"
@sarjarapu
sarjarapu / kubernetes-environment.sh
Created July 11, 2018 20:31
A script file hold all the environment variables for your MongoDB deployments in Kubernetes
OM_PROJECT_ID="<opsmanager_project_id>"
OM_USER_BASE64=$(echo "<opsmanager_userid>" | base64)
OM_API_KEY_BASE64=$(echo "<opsmanager_public_apikey>" | base64)
OM_URL="<opsmanager_uri>"
K8_NAMESPACE="<kubernetes_namespace>"
MONGODB_VERSION="<mongodb_version>"